Advertisement
Guest User

Panzer

a guest
Aug 18th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. // textobject.h
  2. #ifndef TEXTOBJECT_H
  3. #define TEXTOBJECT_H
  4.  
  5. #include <QDebug>
  6.  
  7. class TextObject: public QObject
  8. {
  9.      Q_OBJECT
  10.  
  11.     QString m_text;
  12.  
  13. public:
  14.     TextObject() : m_text("initial")
  15.     {
  16.         qDebug() << "TextObject" << m_text << this;
  17.         connect(this, SIGNAL(textChanged(QString)), this, SLOT(CPP_SLOT_textChanged()));
  18.     }
  19.     Q_PROPERTY(QString text READ getText WRITE setText NOTIFY textChanged)
  20.  
  21.     QString getText() const
  22.     {
  23.         qDebug() << "getText" << m_text;
  24.         return m_text;
  25.     }
  26.  
  27. signals:
  28.  
  29.     void textChanged(QString text);
  30.  
  31. public slots:
  32.     void setText(QString text)
  33.     {
  34.         if (m_text == text)
  35.         {
  36.             qDebug() << "setText" << m_text << "UNCHANGED";
  37.             return;
  38.         }
  39.         qDebug() << "setText" << m_text << "=" << text;
  40.         m_text = text;
  41.         emit textChanged(text);
  42.     }
  43.     void CPP_SLOT_textChanged()
  44.     {
  45.         qDebug() << "CPP_SLOT_textChanged" << m_text;
  46.     }
  47.     void changeTextViaCPP(QString text)
  48.     {
  49.         qDebug() << "changeTextViaCPP" << m_text << "=" << text;
  50.         setText(text);
  51.     }
  52. };
  53.  
  54. #endif // TEXTOBJECT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement