How to call message dialog from qt c++ ?
-
What is the proper way to call a message dialog from c++ ? here is my code so far:
main.qml:
Window { visible: true minimumWidth: 350 minimumHeight: 500 MessageDialog { id: err_msg title: "Error" } }example.cpp:
void Example::some_func(){ // call message dialog here with error message. }Thanks
-
Hi,
Did you already read the C++ QML Integration guide ?
-
Hi,
Did you already read the C++ QML Integration guide ?
-
What is the proper way to call a message dialog from c++ ? here is my code so far:
main.qml:
Window { visible: true minimumWidth: 350 minimumHeight: 500 MessageDialog { id: err_msg title: "Error" } }example.cpp:
void Example::some_func(){ // call message dialog here with error message. }Thanks
@Ahti hi
use signal /slot mechanismWindow { visible: true minimumWidth: 350 minimumHeight: 500 Example{ onErrorSignal : err_msg.show() } MessageDialog { id: err_msg title: "Error" } } //example.cpp: void Example::some_func(){ // call message dialog here with error message., emit a signal emit errorSignal(); } -
@Ahti hi
use signal /slot mechanismWindow { visible: true minimumWidth: 350 minimumHeight: 500 Example{ onErrorSignal : err_msg.show() } MessageDialog { id: err_msg title: "Error" } } //example.cpp: void Example::some_func(){ // call message dialog here with error message., emit a signal emit errorSignal(); } -
@LeLev This doesn't work:
Example{ onErrorSignal : err_msg.show() }mainly because I have set Example as property with rootContext() like this:
main.cpp:
Example e; engine.rootContext()->setContextProperty("example", &e);@Ahti you can une QML Connections type like this
Connections { target: example onErrorSignal : err_msg.show() } -
Hi @Ahti
You can also expose the function as
Q_INVOKABLEor use it aspublic slots:with return type asbool.
And use that function in QML .public: Q_INVOKABLE bool some_func(); // OR public slots: bool some_func();MessageDialog { id: err_msg title: "Error" visible: example.some_func(); }Hope it was of help.
All the best. -
Hi @Ahti
You can also expose the function as
Q_INVOKABLEor use it aspublic slots:with return type asbool.
And use that function in QML .public: Q_INVOKABLE bool some_func(); // OR public slots: bool some_func();MessageDialog { id: err_msg title: "Error" visible: example.some_func(); }Hope it was of help.
All the best. -
@Pradeep-P-N hi, you should tag the OP, not me
@LeLev the reply was from Mobile, so it got missed.