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

Q_INCLUDE_MOC vs Q_DECLARE_OPAQUE_POINTER

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 589 Views
  • 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 Online
    R Online
    Redman
    wrote on last edited by
    #1

    Hi,

    whats the difference between Q_INCLUDE_MOC and Q_DECLARE_OPAQUE_POINTER?
    Maybe let me phrase the question in a different way:
    Which one of the above is more appropriate for my usecase?
    I have fordward declared classes which get used in Q_PORPERTY and signal/slots. For that to work the types must be fully-defined, as stated in qmetatype.h

    static_assert(is_complete<Pointed, void>::value,
                        "Pointer Meta Types must either point to fully-defined types "
                        "or be declared with Q_DECLARE_OPAQUE_POINTER(T *)");
    

    I can get my forwarddeclared classes to be accepted by Q_PROPERTY and signals/slots by using either one of the above mentioned macros.
    So which one should I use?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      What's Q_INCLUDE_MOC?
      Q_DECLARE_OPAQUE_POINTER is definitely well suited for your use case.
      Its doc says:

      This macro enables pointers to forward-declared types (PointerType) to be registered with QMetaType [...]

      R 1 Reply Last reply
      0
      • GrecKoG GrecKo

        What's Q_INCLUDE_MOC?
        Q_DECLARE_OPAQUE_POINTER is definitely well suited for your use case.
        Its doc says:

        This macro enables pointers to forward-declared types (PointerType) to be registered with QMetaType [...]

        R Online
        R Online
        Redman
        wrote on last edited by Redman
        #3

        @GrecKo said in Q_INCLUDE_MOC vs Q_DECLARE_OPAQUE_POINTER:

        What's Q_INCLUDE_MOC?

        I meant Q_MOC_INCLUDE
        which says in the documentation

        This is useful if the types you use as properties or signal/slots arguments are forward declared.
        

        That's why I am not sure which one to use.
        Since they both achieve the same for me right now, I 'd like to know what happens under the hood and which approach is more lightweight?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          felixonmars
          wrote last edited by
          #4

          I got into similar situation today, but I had to use Q_MOC_INCLUDE because the class is a Q_OBJECT in my case. The Qt docs suggest that Q_DECLARE_OPAQUE_POINTER is incompatible in this case.

          Hope this helps!

          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