Guest User

Untitled

a guest
Aug 18th, 2015
199
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //main.qml
  2. import QtQuick 2.5
  3. import QtQuick.Window 2.2
  4. import TextObject 1.0
  5.  
  6. Window {
  7.     visible: true
  8.  
  9.     TextObject{
  10.         id:textObject2
  11.         text:textEdit1.text
  12.     }
  13.  
  14.     TextEdit {
  15.         id:textEdit1
  16.         width: 200
  17.         focus: true
  18.         font.pointSize: 20
  19.         text: textObject2.text
  20.     }
  21. }
  22. //---------------------------------------------------------------------------------------------------------
  23. //main.cpp
  24. #include <QGuiApplication>
  25. #include <QQmlApplicationEngine>
  26. #include <QtQml>
  27. #include "TextObject.h"
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31.     QGuiApplication app(argc, argv);
  32.  
  33.     TextObject textObject2;
  34.  
  35.  
  36.     QQmlApplicationEngine engine;
  37.  
  38.     qmlRegisterType<TextObject, 1>("TextObject", 1, 0, "TextObject");
  39.  
  40.     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  41.  
  42.     return app.exec();
  43. }
  44. //---------------------------------------------------------------------------------------------------------
  45. //TextObject.h
  46. #ifndef TEXTOBJECT_H
  47. #define TEXTOBJECT_H
  48.  
  49. #include <QDebug>
  50.  
  51. class TextObject: public QObject
  52. {
  53.      Q_OBJECT
  54.  
  55.     QString m_text;
  56.  
  57. public:
  58.     TextObject(){}
  59.     Q_PROPERTY(QString text READ getText WRITE setText NOTIFY textChanged)
  60.  
  61.     QString getText() const
  62.     {
  63.         qDebug()<<"getText "<<m_text;
  64.         return m_text;
  65.     }
  66.  
  67. signals:
  68.  
  69.     void textChanged(QString text);
  70.  
  71. public slots:
  72.     void setText(QString text)
  73.     {
  74.  
  75.         if (m_text == text)
  76.             return;
  77.  
  78.         m_text = text;
  79.         qDebug()<<"setText "<<m_text;
  80.         emit textChanged(text);
  81.  
  82.     }
  83. };
  84.  
  85. #endif // TEXTOBJECT_H
RAW Paste Data