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. Optimalisation Qt QML
Forum Updated to NodeBB v4.3 + New Features

Optimalisation Qt QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 589 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    Hi,
    I exchange data between Qt and QML by Q_PROPERTY.
    Please someone tell me how can I optimize exchange bool data? I am currently doing the following:

    Qt:

        Q_PROPERTY(bool rs0State READ rs0State WRITE setRs0State NOTIFY rs0StateChanged)
        Q_PROPERTY(bool rs1State READ rs1State WRITE setRs1State NOTIFY rs1StateChanged)
        Q_PROPERTY(bool rs2State READ rs2State WRITE setRs2State NOTIFY rs2StateChanged)
        Q_PROPERTY(bool rs3State READ rs3State WRITE setRs3State NOTIFY rs3StateChanged)
    

    QML:

    active: if (systemController.rs0State === true)
                            return true
                        else
                            return false
    

    The QBitArray doesnt't work in QML,

    sierdzioS 1 Reply Last reply
    0
    • D Damian7546

      And it is possible send Struct data to QML by Q_PROPERTY ?

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #8

      @Damian7546 https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#sequence-type-to-javascript-array
      you can use vector<bool>, QList<bool>, qvector<bool>
      remember QML works with Java Script. C++ code can not be added to qml simply.

      1 Reply Last reply
      0
      • D Damian7546

        Hi,
        I exchange data between Qt and QML by Q_PROPERTY.
        Please someone tell me how can I optimize exchange bool data? I am currently doing the following:

        Qt:

            Q_PROPERTY(bool rs0State READ rs0State WRITE setRs0State NOTIFY rs0StateChanged)
            Q_PROPERTY(bool rs1State READ rs1State WRITE setRs1State NOTIFY rs1StateChanged)
            Q_PROPERTY(bool rs2State READ rs2State WRITE setRs2State NOTIFY rs2StateChanged)
            Q_PROPERTY(bool rs3State READ rs3State WRITE setRs3State NOTIFY rs3StateChanged)
        

        QML:

        active: if (systemController.rs0State === true)
                                return true
                            else
                                return false
        

        The QBitArray doesnt't work in QML,

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        @Damian7546 said in Optimalisation Qt QML:

        QML:

        active: if (systemController.rs0State === true)
                                return true
                            else
                                return false
        

        This part is an overkill. Do this instead:

        active: systemController.rs0State
        

        (Z(:^

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #3

          Apart from @sierdzio suggestion what is the other optimization are you looking for ?
          Can add more details to your question.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Damian7546
            wrote on last edited by Damian7546
            #4

            @sierdzio thanks for suggestion .

            @dheerendra
            I would like to instead four Q_PROPERTY use only one. I tried with QBitArray but it not possible refer to an item array from QML.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #5

              Then perhaps you can try with an enum set up to be a Q_FLAG.
              Getting it to work on QML side will be a bit tricky but should be possible.

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Damian7546
                wrote on last edited by
                #6

                And it is possible send Struct data to QML by Q_PROPERTY ?

                sierdzioS JoeCFDJ 2 Replies Last reply
                0
                • D Damian7546

                  And it is possible send Struct data to QML by Q_PROPERTY ?

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #7

                  @Damian7546 said in Optimalisation Qt QML:

                  And it is possible send Struct data to QML by Q_PROPERTY ?

                  Yes, look into Q_GADGET.

                  But if you do that, you will most likely end up using more memory than 4 * bool (so 4 * int).

                  (Z(:^

                  1 Reply Last reply
                  0
                  • D Damian7546

                    And it is possible send Struct data to QML by Q_PROPERTY ?

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #8

                    @Damian7546 https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#sequence-type-to-javascript-array
                    you can use vector<bool>, QList<bool>, qvector<bool>
                    remember QML works with Java Script. C++ code can not be added to qml simply.

                    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