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. QML and C++ Integration
Forum Updated to NodeBB v4.3 + New Features

QML and C++ Integration

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 784 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vidyabhushan
    wrote on last edited by
    #1

    Hi,

    I am creating a desktop based application in QML. This application dynamically updates the device status(like ON/OFF ) on the UI. The status is received in the C++ class file, the same status needs to be updated in QML.
    I used Signal Slot mechanism for Integration with C++ and QML.
    The problem encountered is : Only when the signal is emitted from QML the C++ slot is executed in and following the signal emitted from within the C++ slot the QML slot gets executed.

    Is there a mechanism that the QML slot is executed whenever a signal is generated at C++ without any QML signal being generated.

    Or is there any mechanism to update the QML dynamically without any events generated from QML.

    1 Reply Last reply
    0
    • DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      To avoid the loop, you may need to provide some flag argument to your signal: if emitted from QML/C++, you set the flag to true and based on the flag, choose to emit a signal or not in the slot.
      But to be more effective, you should post some code.

      V 1 Reply Last reply
      0
      • DiracsbracketD Diracsbracket

        To avoid the loop, you may need to provide some flag argument to your signal: if emitted from QML/C++, you set the flag to true and based on the flag, choose to emit a signal or not in the slot.
        But to be more effective, you should post some code.

        V Offline
        V Offline
        vidyabhushan
        wrote on last edited by
        #3

        @Diracsbracket
        Thanks for the reply.
        This solution will not fulfil my requirement.
        My requirement is
        I want to change the colour of a circle from red to green or vice versa in QML as and when the status of a device is received from the middleware. This should happen dynamically and without any user intervention. The middleware is integrated with Qt C++.
        What is the best way this can be implemented?
        Kindly help

        DiracsbracketD GrecKoG 2 Replies Last reply
        0
        • V vidyabhushan

          @Diracsbracket
          Thanks for the reply.
          This solution will not fulfil my requirement.
          My requirement is
          I want to change the colour of a circle from red to green or vice versa in QML as and when the status of a device is received from the middleware. This should happen dynamically and without any user intervention. The middleware is integrated with Qt C++.
          What is the best way this can be implemented?
          Kindly help

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @vidyabhushan said in QML and C++ Integration:

          This solution will not fulfil my requirement

          I see... My bad!

          1 Reply Last reply
          0
          • V vidyabhushan

            @Diracsbracket
            Thanks for the reply.
            This solution will not fulfil my requirement.
            My requirement is
            I want to change the colour of a circle from red to green or vice versa in QML as and when the status of a device is received from the middleware. This should happen dynamically and without any user intervention. The middleware is integrated with Qt C++.
            What is the best way this can be implemented?
            Kindly help

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            Only when the signal is emitted from QML the C++ slot is executed in and following the signal emitted from within the C++ slot the QML slot gets executed.

            You have something weird going on, there should be no problem receiving a c++ signal from QML, regardless if a QML signal was emitted before.

            I want to change the colour of a circle from red to green or vice versa in QML as and when the status of a device is received from the middleware. This should happen dynamically and without any user intervention. The middleware is integrated with Qt C++.

            For this usecase, I would recommand going with a Q_PROPERTY(bool deviceIsOn READ deviceIsOn NOTIFY deviceIsOnChanged).
            When the state of the device is changed, emit the notify signal so that the QML side knows it has changed, and it will then call the getter to query the state.

            Thanks to the magic of QML property binding, your QML code will simply become:
            Rectangle { color: cppObject.deviceIsOn ? "green" : "red" }

            More info about exposing c++ properties here : http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-properties

            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