About QML and C++ trouble
-
Hello.
i am new to Qt , i just want to ask a question to you experts.i made a button in .qml file, but i want to make the reaction (open warning window) as C++ codes
when the button is clicked.Could you please tell me what i need, what i have to do.
Thanks for reading
(it will be more thankful if you give me simple, example sources) -
In the your button's
onClicked
signal handler, call the function that opens your warning window.Qt Quick Controls 2 has a ready-made
Button
: https://doc.qt.io/qt-5/qml-qtquick-controls2-button.html -
Thanks for replying
But what i want to know is that,
is there any way to make an warning message (No console) based on C++ code?
i don't know even what kind of function i need to use...plz give me a little bit more help
thanks@Aleph If you write the GUI in qml it's not a good idea to use c++ GUI. Write the backend in c++ but the whole GUI in qml. Why don't you want to use qml to show a warning dialog window? If, on the other hand, you want to handle the button click in c++ (which is a normal thing to do) and under some circumstances want to show a warning, you can emit a signal from a c++ class and receive it in qml where you show the dialog.
-
Thanks for replying
But what i want to know is that,
is there any way to make an warning message (No console) based on C++ code?
i don't know even what kind of function i need to use...plz give me a little bit more help
thanks@Aleph said in About QML and C++ trouble:
is there any way to make an warning message (No console) based on C++ code?
Sorry, I don't quite understand your question. What kind of C++ code do you want to call from QML?
As a starting point, see this article: http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
-
You can declare your C++ function as Q_INVOKABLE and then be able to call it from the QML onClicked or else.
For example:
in header file: Q_INVOKABLE <regular function>
and in QML: onClicked:<regular function>@Eeli-K could you elaborate on the signal. i'm trying to this but was unable(https://forum.qt.io/topic/83671/change-a-state-of-roundbutton-from-c)
-
@Aleph It looks like you're entering into moody waters with no need. As suggested in previous posts, if you write the GUI in QML it's advisable not to use C++ for the GUI as well. You should have most of the components required for good UX in QML, leaving C++ code for the backend (when your applications need to do "complicated" stuff: DB access, calculations, read sensors, etc.)
I'd say take some time and read this introductory book which covers lots of topics related to Qt, mainly from QML and also with some chapters devoted to C++.