Dinamically change qt quick control from c++
Unsolved
QML and Qt Quick
-
Hello. i previously have made a search for this with no result, (may i selected the non apropiated key words, my apologies).
i have a Button made in QML.. what im looking for is to change the Button's text once it is pushed....
The Button block will call a function from my c++ code, from there, i want to change the text of the Button quick control.. is this possible or QML just will serve me as a read-only view controls?
Example:
main.qml:Button{ id : pbtGreetings text : "Click here" onClicked : MySite.onClickButton() }
MySite.cpp
void MySite::onClickButton(){ //something like: getQML("main.qml").pbtGreetings.text = "Pushed!"; }
thanks!
-
@1XU7 Hi
main.qml:Button{ id : pbtGreetings text : "Click here" onClicked : MySite.onClickButton() } Connections { target:MySite function onNewText(s) { pbtGreetings.text=s; } }
MySite.h:
class MySite:public QObject { Q_OBJECT public: Q_INVOKABLE void onClickButton(); signals: void newText(QString s); };
MySite.cpp:
void MySite::onClickButton(){
//something like:
emit newText( "Pushed!");
}