How to call message dialog from qt c++ ?
-
wrote on 19 Jul 2019, 14:52 last edited by
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
wrote on 19 Jul 2019, 16:27 last edited by ODБOï@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(); }
wrote on 19 Jul 2019, 18:37 last edited by Ahti@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);
-
@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);
wrote on 19 Jul 2019, 19:03 last edited by ODБOï@Ahti you can une QML Connections type like this
Connections { target: example onErrorSignal : err_msg.show() }
-
wrote on 22 Jul 2019, 04:47 last edited by Pradeep P N
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. -
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.wrote on 22 Jul 2019, 08:57 last edited by ODБOï@Pradeep-P-N hi, you should tag the OP, not me
-
@Pradeep-P-N hi, you should tag the OP, not me
wrote on 22 Jul 2019, 12:58 last edited by@LeLev the reply was from Mobile, so it got missed.
1/9