Advertisement
Guest User

Untitled

a guest
Nov 13th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import QtQuick 1.0
  2. import test 1.0
  3.  
  4. Rectangle {
  5. width: 360
  6. height: 360
  7. Text {
  8. id: textField
  9. text: qsTr("Hello World")
  10. anchors.centerIn: parent
  11. }
  12. MouseArea {
  13. anchors.fill: parent
  14. onClicked: {
  15. textField.text = "Clicked...";
  16. b.doA(aa);
  17. b.doC(c);
  18. }
  19. }
  20. A{id: aa; test: "bar"}
  21. B{id: b}
  22. C{id: c; a: aa}
  23. }
  24.  
  25. class A : public QObject
  26. {
  27. Q_OBJECT
  28. Q_PROPERTY(QString test READ test WRITE setTest NOTIFY testChanged)
  29. public:
  30. explicit A(QObject *parent = 0);
  31.  
  32. A& operator = (const A &a){
  33. myTest = a.myTest;
  34. return *this;
  35. }
  36.  
  37. A(const A &obj, QObject *parent = 0):
  38. QObject(parent)
  39. {
  40. myTest = obj.myTest;
  41. }
  42.  
  43. QString test(){return myTest;}
  44. void setTest(QString t){
  45. myTest = t;
  46. testChanged(myTest);
  47. }
  48.  
  49. signals:
  50. void testChanged(QString t);
  51.  
  52. public slots:
  53.  
  54. private:
  55. QString myTest;
  56.  
  57.  
  58. };
  59.  
  60. class B : public QObject
  61. {
  62. Q_OBJECT
  63. public:
  64. explicit B(QObject *parent = 0);
  65.  
  66. Q_INVOKABLE void doA(A *a){
  67. qDebug() << "doing A: " << a->test();
  68. }
  69.  
  70. Q_INVOKABLE void doC(C *c){
  71. qDebug() << "doing C: " << c->a()->test();
  72. }
  73.  
  74. };
  75.  
  76. class C : public QObject
  77. {
  78. Q_OBJECT
  79. Q_PROPERTY(A* a READ a WRITE setA NOTIFY aChanged)
  80. public:
  81. explicit C(QObject *parent = 0);
  82.  
  83. A* a(){return myA;}
  84. void setA(A *a){
  85. myA = a;
  86. aChanged(myA);
  87. }
  88.  
  89. signals:
  90. void aChanged(A*);
  91.  
  92. public slots:
  93.  
  94. private:
  95. A *myA;
  96.  
  97. };
  98.  
  99. #include <QtDeclarative>
  100.  
  101. #include "a.h"
  102. #include "b.h"
  103. #include "c.h"
  104.  
  105. Q_DECL_EXPORT int main(int argc, char *argv[])
  106. {
  107. QScopedPointer<QApplication> app(createApplication(argc, argv));
  108. QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
  109.  
  110. qmlRegisterType<A>("test", 1, 0, "A");
  111. qmlRegisterType<B>("test", 1, 0, "B");
  112. qmlRegisterType<C>("test", 1, 0, "C");
  113.  
  114. viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
  115. viewer->setMainQmlFile(QLatin1String("qml/call_test/main.qml"));
  116. viewer->showExpanded();
  117.  
  118. return app->exec();
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement