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->findChild<QObject *>("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->findChild<QObject*>("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