How to call message dialog from qt c++ ?
Unsolved
QML and Qt Quick
-
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 ?
-
@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 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_INVOKABLE
or 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.