[SailfishDevel] Accessing C++ properties from QML
Hi all, i need to access a property of a C++ Class, declared inside another class, from QML. This is the principal class: #ifndef MANAGER_H #define MANAGER_H #include QObject #include QTextStream #include QFile #include monster.h #include move.h #include turnmanager.h class Manager : public QObject { Q_OBJECT public: explicit Manager(QObject *parent = 0); int activeId; QString activeString; int enemyId; Monster active; Monster enemy; Move activeMove; Move enemyMove; Q_INVOKABLE void saveActive(); Q_INVOKABLE void fetchMonster( const int level ); Q_INVOKABLE void assignMoves(Monster monster ); Q_INVOKABLE void setMove( Move move, const int id ); signals: void fetchMonsterDone(); public slots: }; #endif // MANAGER_H this is the Monster Class: #ifndef MONSTER_H #define MONSTER_H #include QObject #include QString #include math.h #include move.h class Monster : public QObject { Q_OBJECT public: explicit Monster(QObject *parent = 0); ... QString name; ... }; #endif // MONSTER_H in my qml page i include the class properly and i have something like this: Page { id: page Manager { id: manager onFetchMonsterDone: { console.log(Fetch done) } } Label { id: label } } after doing some operations with fetchMonster(), the active class has been assigned some values to its properties, i need to access these values from QML in the onFetchMonsterDone, let's say i need to assign to label.text the value of manager.active.name OR i read there are some ways to access end edit QML properties from C++ Can someone help me? ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
Hi, try having a look at this http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html 2015-08-13 14:14 GMT+01:00 Antonio Mancini ziobill...@gmail.com: Hi all, i need to access a property of a C++ Class, declared inside another class, from QML. This is the principal class: #ifndef MANAGER_H #define MANAGER_H #include QObject #include QTextStream #include QFile #include monster.h #include move.h #include turnmanager.h class Manager : public QObject { Q_OBJECT public: explicit Manager(QObject *parent = 0); int activeId; QString activeString; int enemyId; Monster active; Monster enemy; Move activeMove; Move enemyMove; Q_INVOKABLE void saveActive(); Q_INVOKABLE void fetchMonster( const int level ); Q_INVOKABLE void assignMoves(Monster monster ); Q_INVOKABLE void setMove( Move move, const int id ); signals: void fetchMonsterDone(); public slots: }; #endif // MANAGER_H this is the Monster Class: #ifndef MONSTER_H #define MONSTER_H #include QObject #include QString #include math.h #include move.h class Monster : public QObject { Q_OBJECT public: explicit Monster(QObject *parent = 0); ... QString name; ... }; #endif // MONSTER_H in my qml page i include the class properly and i have something like this: Page { id: page Manager { id: manager onFetchMonsterDone: { console.log(Fetch done) } } Label { id: label } } after doing some operations with fetchMonster(), the active class has been assigned some values to its properties, i need to access these values from QML in the onFetchMonsterDone, let's say i need to assign to label.text the value of manager.active.name OR i read there are some ways to access end edit QML properties from C++ Can someone help me? ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
for properties system you should use Q_PROPERTY macro inside your class. -- Исходное сообщение -- От: Antonio Mancini ziobill...@gmail.com Кому: Sailfish OS Developers devel@lists.sailfishos.org Отправлено: 13.08.2015 18:14:29 Тема: [SailfishDevel] Accessing C++ properties from QML Hi all, i need to access a property of a C++ Class, declared inside another class, from QML. This is the principal class: #ifndef MANAGER_H #define MANAGER_H #include QObject #include QTextStream #include QFile #include monster.h #include move.h #include turnmanager.h class Manager : public QObject { Q_OBJECT public: explicit Manager(QObject *parent = 0); int activeId; QString activeString; int enemyId; Monster active; Monster enemy; Move activeMove; Move enemyMove; Q_INVOKABLE void saveActive(); Q_INVOKABLE void fetchMonster( const int level ); Q_INVOKABLE void assignMoves(Monster monster ); Q_INVOKABLE void setMove( Move move, const int id ); signals: void fetchMonsterDone(); public slots: }; #endif // MANAGER_H this is the Monster Class: #ifndef MONSTER_H #define MONSTER_H #include QObject #include QString #include math.h #include move.h class Monster : public QObject { Q_OBJECT public: explicit Monster(QObject *parent = 0); ... QString name; ... }; #endif // MONSTER_H in my qml page i include the class properly and i have something like this: Page { id: page Manager { id: manager onFetchMonsterDone: { console.log(Fetch done) } } Label { id: label } } after doing some operations with fetchMonster(), the active class has been assigned some values to its properties, i need to access these values from QML in the onFetchMonsterDone, let's say i need to assign to label.text the value of manager.active.name OR i read there are some ways to access end edit QML properties from C++ Can someone help me?___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
Thanks, actually i had already seen that but couldn't accomplish much, now i tried again and i managed to access and edit qml properties, but the QML object doesn't update. i use this code in a c++ method QQmlEngine engine; QQmlComponent component (engine, /usr/share/harbour-pocketmonsters/qml/pages/FirstPage.qml); QObject *object = component.create(); QObject *label = object-findChildQObject*(label); cout label-property(text).toString(); if (label) label-setProperty(text, active.name); cout label-property(text).toString(); the output of cout is correct, but the label doesn't update The console shows these errors, but i think they are irrelevant since the output is correct [W] unknown:108 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:108: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:94 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:94: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:178 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:178: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:331 - file:///usr/lib/qt5/qml/Sailfish/Silica/private/PulleyMenuBase.qml:331: ReferenceError: __silica_applicationwindow_instance is not defined 2015-08-13 15:17 GMT+02:00 Andrea Bernabei and.berna...@gmail.com: Hi, try having a look at this http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html 2015-08-13 14:14 GMT+01:00 Antonio Mancini ziobill...@gmail.com: Hi all, i need to access a property of a C++ Class, declared inside another class, from QML. This is the principal class: #ifndef MANAGER_H #define MANAGER_H #include QObject #include QTextStream #include QFile #include monster.h #include move.h #include turnmanager.h class Manager : public QObject { Q_OBJECT public: explicit Manager(QObject *parent = 0); int activeId; QString activeString; int enemyId; Monster active; Monster enemy; Move activeMove; Move enemyMove; Q_INVOKABLE void saveActive(); Q_INVOKABLE void fetchMonster( const int level ); Q_INVOKABLE void assignMoves(Monster monster ); Q_INVOKABLE void setMove( Move move, const int id ); signals: void fetchMonsterDone(); public slots: }; #endif // MANAGER_H this is the Monster Class: #ifndef MONSTER_H #define MONSTER_H #include QObject #include QString #include math.h #include move.h class Monster : public QObject { Q_OBJECT public: explicit Monster(QObject *parent = 0); ... QString name; ... }; #endif // MONSTER_H in my qml page i include the class properly and i have something like this: Page { id: page Manager { id: manager onFetchMonsterDone: { console.log(Fetch done) } } Label { id: label } } after doing some operations with fetchMonster(), the active class has been assigned some values to its properties, i need to access these values from QML in the onFetchMonsterDone, let's say i need to assign to label.text the value of manager.active.name OR i read there are some ways to access end edit QML properties from C++ Can someone help me? ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
for properties system you should use Q_PROPERTY macro inside your class. Since i have to access properties of a class declared inside another class i find using the macro Q_PROPERTY a little confusing. Actually, I think you're creating a new instance of the FirstPage.qml component using this code. But, Sailfish should have already created its own instance of that page when it started up. You might instead try retrieving a view of the Sailfish instance and going from there, something like this: QQuickView *view = SailfishApp::createView(); QObject *object = view-rootObject(); QObject *label = object-findChildQObject *(label); --John I tried this, it compiles, after including sailfishapp.h and QQuickItem, but now there's no output, as it can't find the proper object or the SailfishApp::createView() creates a new, empty view The code is this: ... QQuickView *view = SailfishApp::createView(); QObject *object = view-rootObject(); QObject *label = object-findChildQObject*(label); QQmlProperty property(label, text); cout Read before: property.read().toString() endl; if (label) { cout true; property.write(active.name); } else cout false endl; cout Read after:property.read().toString() endl; fetchMonsterDone(); ... the output is: Read before: false Read after: [D] onFetchMonsterDone:51 - Fetch done ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Sending SMS via Telepathy: Error Channel Dispatcher .. does not support interface CD.I.Messages
Hi All I now have a working work-around: My app can (finally) send SMSes via Telepathy again. Previously I was using ContactMessenger object. Now I have found a vector using the ConversationChannel object. It took a lot of hacking around due to my weak understanding of c++, but in the end I hit on a solution that required minimal change to both my code, and to ConversationChannel. I grabbed the code below: https://github.com/nemomobile/nemo-qml-plugin-messages/blob/master/src/conversationchannel.h https://github.com/nemomobile/nemo-qml-plugin-messages/blob/master/src/conversationchannel.cpp then pimped it slightly so it that on a successful sendMessage, it emits the signal finished Previously, using ContactMessenger my code was void TelepathyHelper::sendSMS(const QString contactIdentifier, const QString message) { Tp::AccountPtr acc = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME, QLatin1String(/org/freedesktop/Telepathy/Account/ring/tel/account0)); messenger = Tp::ContactMessenger::create(acc, contactIdentifier); connect(messenger-sendMessage(message), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onSendMessageFinished(Tp::PendingOperation*))); } Now (temporarily) using ConversationChannel my code is: void TelepathyHelper::sendSMS(const QString contactIdentifier, const QString message) { ConversationChannel *conversationChannel = new ConversationChannel(/org/freedesktop/Telepathy/Account/ring/tel/account0, contactIdentifier); connect(conversationChannel, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onSendMessageFinished(Tp::PendingOperation*))); //this works! SMS is sent yippeee !!! conversationChannel-sendMessage(message); } Cheers Chris Am 2015-08-12 14:26, schrieb christopher.l...@thurweb.ch: Hi Matt . My main focus now is finding a code approach that works with the current installed packages. I think I have found a vector, but need to do some more coding to know for sure. . Thanks Chris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
You can try to use signals and slots like this: Header class // ... { // ... signals: void somethingWasDone(); // } Source // ... someMethod() { // Do something emit somethingWasDone(); } // ... QML // ... Connections { target: // Your module onSomethingWasDone: // Change properties } // ... More about this you can see at the video: https://www.youtube.com/watch?v=R59lpwNy9WE Regards, Petr [Linux User Group Udmurtia](https://udmlug.wordpress.com/) Original Message Subject: Re: [SailfishDevel] Accessing C++ properties from QML Time (UTC): August 13 2015 5:26 pm From: ziobill...@gmail.com To: devel@lists.sailfishos.org CC: for properties system you should use Q_PROPERTY macro inside your class. Since i have to access properties of a class declared inside another class i find using the macro Q_PROPERTY a little confusing. Actually, I think you're creating a new instance of the FirstPage.qml component using this code. But, Sailfish should have already created its own instance of that page when it started up. You might instead try retrieving a view of the Sailfish instance and going from there, something like this: QQuickView *view = SailfishApp::createView(); QObject *object = view-rootObject(); QObject *label = object-findChildQObject *(label); --John I tried this, it compiles, after including sailfishapp.h and QQuickItem, but now there's no output, as it can't find the proper object or the SailfishApp::createView() creates a new, empty view The code is this: ... QQuickView *view = SailfishApp::createView(); QObject *object = view-rootObject(); QObject *label = object-findChildQObject*(label); QQmlProperty property(label, text); cout Read before: property.read().toString() endl; if (label) { cout true; property.write(active.name); } else cout false endl; cout Read after: property.read().toString() endl; fetchMonsterDone(); ... the output is: Read before: false Read after: [D] onFetchMonsterDone:51 - Fetch done___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] Accessing C++ properties from QML
Actually, I think you're creating a new instance of the FirstPage.qml component using this code. But, Sailfish should have already created its own instance of that page when it started up. You might instead try retrieving a view of the Sailfish instance and going from there, something like this: QQuickView *view = SailfishApp::createView(); QObject *object = view-rootObject(); QObject *label = object-findChildQObject *(label); --John On 8/13/15 10:51 AM, Antonio Mancini wrote: Thanks, actually i had already seen that but couldn't accomplish much, now i tried again and i managed to access and edit qml properties, but the QML object doesn't update. i use this code in a c++ method QQmlEngine engine; QQmlComponent component (engine, /usr/share/harbour-pocketmonsters/qml/pages/FirstPage.qml); QObject *object = component.create(); QObject *label = object-findChildQObject*(label); cout label-property(text).toString(); if (label) label-setProperty(text, active.name http://active.name); cout label-property(text).toString(); the output of cout is correct, but the label doesn't update The console shows these errors, but i think they are irrelevant since the output is correct [W] unknown:108 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:108: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:94 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:94: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:178 - file:///usr/lib/qt5/qml/Sailfish/Silica/Page.qml:178: ReferenceError: __silica_applicationwindow_instance is not defined [W] unknown:331 - file:///usr/lib/qt5/qml/Sailfish/Silica/private/PulleyMenuBase.qml:331: ReferenceError: __silica_applicationwindow_instance is not defined 2015-08-13 15:17 GMT+02:00 Andrea Bernabei and.berna...@gmail.com mailto:and.berna...@gmail.com: Hi, try having a look at this http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html 2015-08-13 14:14 GMT+01:00 Antonio Mancini ziobill...@gmail.com mailto:ziobill...@gmail.com: Hi all, i need to access a property of a C++ Class, declared inside another class, from QML. This is the principal class: #ifndef MANAGER_H #define MANAGER_H #include QObject #include QTextStream #include QFile #include monster.h #include move.h #include turnmanager.h class Manager : public QObject { Q_OBJECT public: explicit Manager(QObject *parent = 0); int activeId; QString activeString; int enemyId; Monster active; Monster enemy; Move activeMove; Move enemyMove; Q_INVOKABLE void saveActive(); Q_INVOKABLE void fetchMonster( const int level ); Q_INVOKABLE void assignMoves(Monster monster ); Q_INVOKABLE void setMove( Move move, const int id ); signals: void fetchMonsterDone(); public slots: }; #endif // MANAGER_H this is the Monster Class: #ifndef MONSTER_H #define MONSTER_H #include QObject #include QString #include math.h #include move.h class Monster : public QObject { Q_OBJECT public: explicit Monster(QObject *parent = 0); ... QString name; ... }; #endif // MONSTER_H in my qml page i include the class properly and i have something like this: Page { id: page Manager { id: manager onFetchMonsterDone: { console.log(Fetch done) } } Label { id: label } } after doing some operations with fetchMonster(), the active class has been assigned some values to its properties, i need to access these values from QML in the onFetchMonsterDone, let's say i need to assign to label.text the value of manager.active.name http://manager.active.name OR i read there are some ways to access end edit QML properties from C++ Can someone help me? ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org