Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.0
- import test 1.0
- Rectangle {
- width: 360
- height: 360
- Text {
- id: textField
- text: qsTr("Hello World")
- anchors.centerIn: parent
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- textField.text = "Clicked...";
- b.doA(aa);
- b.doC(c);
- }
- }
- A{id: aa; test: "bar"}
- B{id: b}
- C{id: c; a: aa}
- }
- class A : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QString test READ test WRITE setTest NOTIFY testChanged)
- public:
- explicit A(QObject *parent = 0);
- A& operator = (const A &a){
- myTest = a.myTest;
- return *this;
- }
- A(const A &obj, QObject *parent = 0):
- QObject(parent)
- {
- myTest = obj.myTest;
- }
- QString test(){return myTest;}
- void setTest(QString t){
- myTest = t;
- testChanged(myTest);
- }
- signals:
- void testChanged(QString t);
- public slots:
- private:
- QString myTest;
- };
- class B : public QObject
- {
- Q_OBJECT
- public:
- explicit B(QObject *parent = 0);
- Q_INVOKABLE void doA(A *a){
- qDebug() << "doing A: " << a->test();
- }
- Q_INVOKABLE void doC(C *c){
- qDebug() << "doing C: " << c->a()->test();
- }
- };
- class C : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(A* a READ a WRITE setA NOTIFY aChanged)
- public:
- explicit C(QObject *parent = 0);
- A* a(){return myA;}
- void setA(A *a){
- myA = a;
- aChanged(myA);
- }
- signals:
- void aChanged(A*);
- public slots:
- private:
- A *myA;
- };
- #include <QtDeclarative>
- #include "a.h"
- #include "b.h"
- #include "c.h"
- Q_DECL_EXPORT int main(int argc, char *argv[])
- {
- QScopedPointer<QApplication> app(createApplication(argc, argv));
- QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
- qmlRegisterType<A>("test", 1, 0, "A");
- qmlRegisterType<B>("test", 1, 0, "B");
- qmlRegisterType<C>("test", 1, 0, "C");
- viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
- viewer->setMainQmlFile(QLatin1String("qml/call_test/main.qml"));
- viewer->showExpanded();
- return app->exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement