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. Q_GADGET vs Q_OBJECT
Forum Updated to NodeBB v4.3 + New Features

Q_GADGET vs Q_OBJECT

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 18.2k 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.
  • X Offline
    X Offline
    xylosper
    wrote on last edited by
    #1

    I can use Q_GADGET or Q_OBJECT to expose C++ object into QML.
    If my object can be implemented through Q_GADGET, that is no need of inheritance of QObject and no need of signals, which one should I use?
    Should I always prefer Q_GADGET to Q_OBJECT whenever possible?
    Or, is it always better to use Q_OBJECT than Q_GADGET?
    If it depends on situation, what would decide better one?

    raven-worxR 1 Reply Last reply
    0
    • X xylosper

      I can use Q_GADGET or Q_OBJECT to expose C++ object into QML.
      If my object can be implemented through Q_GADGET, that is no need of inheritance of QObject and no need of signals, which one should I use?
      Should I always prefer Q_GADGET to Q_OBJECT whenever possible?
      Or, is it always better to use Q_OBJECT than Q_GADGET?
      If it depends on situation, what would decide better one?

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

      @xylosper
      Q_GADGET is more or less the MOC part of Q_OBJECT.
      So if you can live without the features provided by QObject class you are good to go.

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

      X 1 Reply Last reply
      1
      • Q Offline
        Q Offline
        qnope
        wrote on last edited by
        #3

        Q_GADGET does not allow signal

        1 Reply Last reply
        1
        • raven-worxR raven-worx

          @xylosper
          Q_GADGET is more or less the MOC part of Q_OBJECT.
          So if you can live without the features provided by QObject class you are good to go.

          X Offline
          X Offline
          xylosper
          wrote on last edited by
          #4

          @raven-worx
          In that case, I'll stick to Q_GADGET as much as possible. Thank you!

          @qnope
          I've already mentioned 'no need of signals'. Thank you.

          raven-worxR 1 Reply Last reply
          1
          • X xylosper

            @raven-worx
            In that case, I'll stick to Q_GADGET as much as possible. Thank you!

            @qnope
            I've already mentioned 'no need of signals'. Thank you.

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

            @xylosper
            if you are forced to use QObjects derives instead, you most probably will get compile errors anyway.

            --- 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
            0

            • Login

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