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. What is the difference between macros Q_INVOKABLE and Q_PROPERTY?
Forum Updated to NodeBB v4.3 + New Features

What is the difference between macros Q_INVOKABLE and Q_PROPERTY?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 2.6k Views 2 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.
  • R Offline
    R Offline
    Ronak5
    wrote on last edited by
    #1

    I know the basic usage of both the macros. I've using Q_PROPERTY to access the cpp objects in qml.
    Lately I came across Q_INVOKABLE also and I read it can used by qt moc to access member functions in qml.
    I'm bit confused regarding on what basis and how do I decide which macro to be used and when? Thanks.

    raven-worxR Pablo J. RoginaP 2 Replies Last reply
    0
    • R Ronak5

      I know the basic usage of both the macros. I've using Q_PROPERTY to access the cpp objects in qml.
      Lately I came across Q_INVOKABLE also and I read it can used by qt moc to access member functions in qml.
      I'm bit confused regarding on what basis and how do I decide which macro to be used and when? Thanks.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Ronak5 said in What is the difference between macros Q_INVOKABLE and Q_PROPERTY?:

      I'm bit confused regarding on what basis and how do I decide which macro to be used and when?

      Q_PROPERTY is a property (with a getter, maybe a setter, notifier signal, etc) which enables you bindings etc.

      Q_INVOKABLE simply marks a method to be callable via moc (and thus also via QML for example), nothing more. Similar to slots for example.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      6
      • R Ronak5

        I know the basic usage of both the macros. I've using Q_PROPERTY to access the cpp objects in qml.
        Lately I came across Q_INVOKABLE also and I read it can used by qt moc to access member functions in qml.
        I'm bit confused regarding on what basis and how do I decide which macro to be used and when? Thanks.

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @Ronak5 you may want to check some of the examples in the documentation about The Property System. You'll see usage of READ, WRITE and NOTIFY for instance.

         Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
        

        And for Q_INVOKABLE and following with that example, you could imagine a method applyPriority for example so if you apply Q_INVOKABLE to it, it could be called from some other C++ classes or even from QML as mentioned before.

        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
        1

        • Login

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