Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. About QML and C++ trouble
QtWS25 Last Chance

About QML and C++ trouble

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 5 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aleph
    wrote on last edited by
    #1

    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)

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Aleph
        wrote on last edited by
        #3

        @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

        E JKSHJ 2 Replies Last reply
        0
        • A Aleph

          @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

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          1
          • A Aleph

            @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

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @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

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            2
            • E Offline
              E Offline
              Eyal Erez
              wrote on last edited by
              #6

              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)

              1 Reply Last reply
              0
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @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++.

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved