Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use of Qt Property

Use of Qt Property

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 1.9k 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.
  • H Offline
    H Offline
    hjohn
    wrote on last edited by hjohn
    #1

    I have go through
    http://doc.qt.io/archives/qt-4.8/properties.html#requirements-for-declaring-properties

    https://forum.qt.io/topic/35142/solved-what-s-the-purpose-of-the-qt-property-system

    links.But I do not understand purpose of it.One is in QML. But I want to use it without QML.
    Here in code

    QObject *object = button;
    
    button->setDown(true);
    object->setProperty("down", true);
    

    does it mean that object->setproperty() is accessing Q_PROPERTY().

    sierdzioS 1 Reply Last reply
    0
    • H hjohn

      I have go through
      http://doc.qt.io/archives/qt-4.8/properties.html#requirements-for-declaring-properties

      https://forum.qt.io/topic/35142/solved-what-s-the-purpose-of-the-qt-property-system

      links.But I do not understand purpose of it.One is in QML. But I want to use it without QML.
      Here in code

      QObject *object = button;
      
      button->setDown(true);
      object->setProperty("down", true);
      

      does it mean that object->setproperty() is accessing Q_PROPERTY().

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

      @hjohn said in Use of Qt Property:

      Is it mean that object->setproperty() is accessing Q_PROPERTY().

      Yes.

      (Z(:^

      H 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @hjohn said in Use of Qt Property:

        Is it mean that object->setproperty() is accessing Q_PROPERTY().

        Yes.

        H Offline
        H Offline
        hjohn
        wrote on last edited by hjohn
        #3

        @sierdzio

        We can setDown button directly by using

        
        button->setDown(true);
        
        

        then what is the purpose of setting property using

        object->setProperty("down", true);
        
        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          what is the purpose of setting property using [setProperty]

          Well, in this case it does not make any sense to use the property.

          It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

          It may also make some sense if you're working with QObjects you don't know directly (you have no #include for them), then you can query the meta object system for all the properties.

          Also, it might be a way of hiding the interface - you can expose the Q_PROPERTY but keep your methods private. I don't quite see why you would do that, but you can ;-) Perhaps in connection with MEMBER properties it would work really well (then there is no need for any access methods at all == less code to write).

          Plus other uses mentioned in the other thread.

          As you say, though, properties make most sense in QML. In C++, you using methods directly is simpler and faster.

          (Z(:^

          H 2 Replies Last reply
          3
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Properties are also used to provide a generic way to animate, see QPropertyAnimation

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3
            • sierdzioS sierdzio

              what is the purpose of setting property using [setProperty]

              Well, in this case it does not make any sense to use the property.

              It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

              It may also make some sense if you're working with QObjects you don't know directly (you have no #include for them), then you can query the meta object system for all the properties.

              Also, it might be a way of hiding the interface - you can expose the Q_PROPERTY but keep your methods private. I don't quite see why you would do that, but you can ;-) Perhaps in connection with MEMBER properties it would work really well (then there is no need for any access methods at all == less code to write).

              Plus other uses mentioned in the other thread.

              As you say, though, properties make most sense in QML. In C++, you using methods directly is simpler and faster.

              H Offline
              H Offline
              hjohn
              wrote on last edited by
              #6

              @sierdzio
              Can you link any example of proper use!

              sierdzioS 1 Reply Last reply
              0
              • H hjohn

                @sierdzio
                Can you link any example of proper use!

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

                @hjohn said in Use of Qt Property:

                @sierdzio
                Can you link any example of proper use!

                You have already written the code for using properties. If you have any specific case in mind, please tell me which one.

                (Z(:^

                1 Reply Last reply
                0
                • sierdzioS sierdzio

                  what is the purpose of setting property using [setProperty]

                  Well, in this case it does not make any sense to use the property.

                  It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

                  It may also make some sense if you're working with QObjects you don't know directly (you have no #include for them), then you can query the meta object system for all the properties.

                  Also, it might be a way of hiding the interface - you can expose the Q_PROPERTY but keep your methods private. I don't quite see why you would do that, but you can ;-) Perhaps in connection with MEMBER properties it would work really well (then there is no need for any access methods at all == less code to write).

                  Plus other uses mentioned in the other thread.

                  As you say, though, properties make most sense in QML. In C++, you using methods directly is simpler and faster.

                  H Offline
                  H Offline
                  hjohn
                  wrote on last edited by
                  #8

                  @sierdzio said in Use of Qt Property:

                  It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

                  Any Example related this!!

                  sierdzioS 1 Reply Last reply
                  0
                  • H hjohn

                    @sierdzio said in Use of Qt Property:

                    It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

                    Any Example related this!!

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

                    @hjohn said in Use of Qt Property:

                    @sierdzio said in Use of Qt Property:

                    It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

                    Any Example related this!!

                    As mentioned in the docs: https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod

                    QMetaObject::invokeMethod(thread, "quit", Qt::QueuedConnection);
                    

                    This is similar to just connecting to the quit slot in a queue:

                    connect(someQObject, &SomeClass::someSignal, thread, &QThread::quit, Qt::QueuedConnection);
                    

                    (Z(:^

                    H 1 Reply Last reply
                    2
                    • sierdzioS sierdzio

                      @hjohn said in Use of Qt Property:

                      @sierdzio said in Use of Qt Property:

                      It may make sense if you want to execute a method in a separate thread, then you can order a queued invocation (and stop worrying about mutexes and such).

                      Any Example related this!!

                      As mentioned in the docs: https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod

                      QMetaObject::invokeMethod(thread, "quit", Qt::QueuedConnection);
                      

                      This is similar to just connecting to the quit slot in a queue:

                      connect(someQObject, &SomeClass::someSignal, thread, &QThread::quit, Qt::QueuedConnection);
                      
                      H Offline
                      H Offline
                      hjohn
                      wrote on last edited by
                      #10

                      @sierdzio How to set property of it using Q_PROPERTY()

                      sierdzioS 1 Reply Last reply
                      0
                      • H hjohn

                        @sierdzio How to set property of it using Q_PROPERTY()

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

                        @hjohn said in Use of Qt Property:

                        @sierdzio How to set property of it using Q_PROPERTY()

                        I don't understand the question. How to set what property? What is "it" referring to?

                        And what has Q_PROPERTY to do with it? That macro only declares the property, it is not used to set anything.

                        (Z(:^

                        1 Reply Last reply
                        4

                        • Login

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