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)


  • Moderators

    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



  • @JKSH

    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.


  • Moderators

    @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


Log in to reply