Well, lets say no one will argue with the above statement ;-)Seems to be a very stupid question from me?!?!?!
Its all in the docs:
http://doc.qt.io/qt-5/qtqml-cppinteg...mlfromcpp.html
(see Accessing Members of a QML Object Type from C++)
Well, lets say no one will argue with the above statement ;-)Seems to be a very stupid question from me?!?!?!
Its all in the docs:
http://doc.qt.io/qt-5/qtqml-cppinteg...mlfromcpp.html
(see Accessing Members of a QML Object Type from C++)
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
codeman (13th July 2017)
Well,
first of all thank you for reply me. I read the docs. But I dont find the place where it describes
accessing some property of the whatever.qml file from MyPlugin{}, which is loaded from qml.exe by the way.
The docs describes accessing it from main.cpp where I load the whatever.qml in fix manner. I dont provide a main.cpp. Thats my problem.
Perhaps I overseen something....
Accessing QML properties from C++ is the same no matter where you are in your C++ code, main or not.
Notice that the heading of that segment reads "Accessing Members of a QML Object Type from C++" and not "Accessing Members of a QML Object Type from main.cpp".
In addition, in that section of the documentation main is not mentioned at all, the code examples there are totally agnostic to any scope in the code.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Hello,
ok I make it clearer.
When I load my qml file through qml.exe it loads the qml file and my property string mystring is equal to "Hello".Qt Code:
Rectangle{ id::root property string mystring:"Hello" Button{ id: btnTest width:140 height: 30 text: "btnTest" onClicked: { console.log(root.mystring) } MyPlugin{ id:plugin1 Component.onCompleted: { } } }To copy to clipboard, switch view to plain text mode
Then in MyPlugin::componentComplete I make this:
Qt Code:
QQmlEngine *mrtEngine = qmlEngine(this); QQmlComponent component(mrtEngine, "path/to/file.qml"); qCritical() << "Property value:" << QQmlProperty::read(object, "mystring").toString(); QQmlProperty::write(object, "mystring", "Hello QtCentre"); delete object;To copy to clipboard, switch view to plain text mode
So now when I click my Button mystring is equal to "Hello" and not "Hello QtCentre"?!?
Which qml file are you loading with 'path/to/file.qml'?
The QML file posted above with the root object?
And you are doing it from the plugin code?
If so this makes no sense to me, as your plugin creates a new root object where itself is also initialized??
otherwise please elaborate more.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
this is my "path/to/file.qml"
Qt Code:
Rectangle{ id::root property string mystring:"Hello" Button{ id: btnTest width:140 height: 30 text: "btnTest" onClicked: { console.log(root.mystring) } MyPlugin{ id:plugin1 Component.onCompleted: { } } }To copy to clipboard, switch view to plain text mode
Yes you are right. The qml.exe is loading 'path/to/file.qml' and then my plugin is also handling the 'path/to/file.qml' file.
My goal is to modify loaded qml file through the plugins in it...
The C++ code you posted, is it in your plugin or application?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
It is in my Plugin as I saidThen in MyPlugin::componentComplete I make this:
Qt Code:
QQmlEngine *mrtEngine = qmlEngine(this); QQmlComponent component(mrtEngine, "path/to/file.qml"); qCritical() << "Property value:" << QQmlProperty::read(object, "mystring").toString(); QQmlProperty::write(object, "mystring", "Hello QtCentre"); delete object;To copy to clipboard, switch view to plain text mode
At least for me it hard to follow.
It seems something in your setup, is wrong, but its hard to say what without seeing the full picture.
Try uploading your project as a zip here and we can then take a better look.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks