Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Questions about Q_PROPERTY and migration (Qt5 -> Qt6)
Forum Update on Monday, May 27th 2025

Questions about Q_PROPERTY and migration (Qt5 -> Qt6)

Scheduled Pinned Locked Moved Unsolved Qt 6
migrationqt5.15.2qt6.4.1questions
3 Posts 2 Posters 978 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.
  • M Offline
    M Offline
    mipr
    wrote on 9 Jan 2023, 14:56 last edited by mipr 1 Sept 2023, 14:58
    #1

    Hi,

    I am migrating the Qt version of my application (from 5.15 to 6.4).
    And I have compilation errors and one in particular :

    Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined
    

    I found some links that explain why this error appears :

    • What's new in QMetaType + QVariant
    • Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined (Qt Forum)

    But I didn't understand everything... So I have many questions

    1. What is an opaque pointer ?
    My hypothesis is that it is a pointer to an object whose behaviour is unknown (like a class in a library where we only have access to the header). Therefore, a pointer to a known class (that we have created and that is in the same module for example) is not an opaque pointer.
    Am I right ?

    2. If I have a custom object like in this code :

    Q_PROPERTY(Camera activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
    

    I need to replace include "Camera.h" by Q_MOC_INCLUDE("Camera.h"). Is it correct ?

    3. If I have a pointer of a custom object

    Q_PROPERTY(Camera* activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
    

    Should I need to replace the Q_MOC_INCLUDE by a Q_DECLARE_OPAQUE_POINTER ?

    #ifndef OPAQUE_Camera
    #define OPAQUE_Camera
    Q_DECLARE_OPAQUE_POINTER(Camera*)
    #endif // OPAQUE_Camera
    

    4. If I have a QList of pointer

    Q_PROPERTY(QList<Camera*> cameras READ getCameras NOTIFY camerasChanged)
    

    Is the previous Q_DECLARE_OPAQUE_POINTER correct ?

    5. If I have a Camera object and a QList<Camera*>, what should I use ?

    Thanks for your help !

    S 1 Reply Last reply 10 Jan 2023, 12:12
    0
    • M mipr
      9 Jan 2023, 14:56

      Hi,

      I am migrating the Qt version of my application (from 5.15 to 6.4).
      And I have compilation errors and one in particular :

      Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined
      

      I found some links that explain why this error appears :

      • What's new in QMetaType + QVariant
      • Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined (Qt Forum)

      But I didn't understand everything... So I have many questions

      1. What is an opaque pointer ?
      My hypothesis is that it is a pointer to an object whose behaviour is unknown (like a class in a library where we only have access to the header). Therefore, a pointer to a known class (that we have created and that is in the same module for example) is not an opaque pointer.
      Am I right ?

      2. If I have a custom object like in this code :

      Q_PROPERTY(Camera activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
      

      I need to replace include "Camera.h" by Q_MOC_INCLUDE("Camera.h"). Is it correct ?

      3. If I have a pointer of a custom object

      Q_PROPERTY(Camera* activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
      

      Should I need to replace the Q_MOC_INCLUDE by a Q_DECLARE_OPAQUE_POINTER ?

      #ifndef OPAQUE_Camera
      #define OPAQUE_Camera
      Q_DECLARE_OPAQUE_POINTER(Camera*)
      #endif // OPAQUE_Camera
      

      4. If I have a QList of pointer

      Q_PROPERTY(QList<Camera*> cameras READ getCameras NOTIFY camerasChanged)
      

      Is the previous Q_DECLARE_OPAQUE_POINTER correct ?

      5. If I have a Camera object and a QList<Camera*>, what should I use ?

      Thanks for your help !

      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 10 Jan 2023, 12:12 last edited by
      #2

      @mipr said in Questions about Q_PROPERTY and migration (Qt5 -> Qt6):

      [...]

      1. What is an opaque pointer ?
      My hypothesis is that it is a pointer to an object whose behaviour is unknown (like a class in a library where we only have access to the header). Therefore, a pointer to a known class (that we have created and that is in the same module for example) is not an opaque pointer.
      Am I right ?

      No. Opaque pointer is a pointer about which compiler knows nothing apart from name. In other words: a pointer to forward-declared type.

      For example:

      class QString;
      
      QString *something;
      

      In this example, QString is forward-declared. The compiler knows only it's type (it's a class) and name ("QString"), but knows nothing else (not even methods inside of it like QString::isEmpty()).

      Typically you will have forward-declared types in headers (to speed up compilation time) and only actually include the full data (#include <QString>;) in the source file.

      In Qt 6, types of Qt properties must be fully defined. So, in simplest terms:

      class QString; // BAD in Qt6!
      #include <QString>; // GOOD in Qt6!
      Q_PROPERTY(QString something ...)
      

      2. If I have a custom object like in this code :

      Q_PROPERTY(Camera activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
      

      I need to replace include "Camera.h" by Q_MOC_INCLUDE("Camera.h"). Is it correct ?

      No need to replace anything. A non-pointer has to be fully declared anyway so no change is necessary.

      3. If I have a pointer of a custom object

      Q_PROPERTY(Camera* activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
      

      Should I need to replace the Q_MOC_INCLUDE by a Q_DECLARE_OPAQUE_POINTER ?

      #ifndef OPAQUE_Camera
      #define OPAQUE_Camera
      Q_DECLARE_OPAQUE_POINTER(Camera*)
      #endif // OPAQUE_Camera
      

      No, it should be enough to use either #include (if you don't care about forward declarations) or Q_MOC_INCLUDE.

      4. If I have a QList of pointer

      Q_PROPERTY(QList<Camera*> cameras READ getCameras NOTIFY camerasChanged)
      

      Is the previous Q_DECLARE_OPAQUE_POINTER correct ?

      I don't know.

      5. If I have a Camera object and a QList<Camera*>, what should I use ?

      I don't understand the question, sorry.

      (Z(:^

      M 1 Reply Last reply 10 Jan 2023, 16:42
      3
      • S sierdzio
        10 Jan 2023, 12:12

        @mipr said in Questions about Q_PROPERTY and migration (Qt5 -> Qt6):

        [...]

        1. What is an opaque pointer ?
        My hypothesis is that it is a pointer to an object whose behaviour is unknown (like a class in a library where we only have access to the header). Therefore, a pointer to a known class (that we have created and that is in the same module for example) is not an opaque pointer.
        Am I right ?

        No. Opaque pointer is a pointer about which compiler knows nothing apart from name. In other words: a pointer to forward-declared type.

        For example:

        class QString;
        
        QString *something;
        

        In this example, QString is forward-declared. The compiler knows only it's type (it's a class) and name ("QString"), but knows nothing else (not even methods inside of it like QString::isEmpty()).

        Typically you will have forward-declared types in headers (to speed up compilation time) and only actually include the full data (#include <QString>;) in the source file.

        In Qt 6, types of Qt properties must be fully defined. So, in simplest terms:

        class QString; // BAD in Qt6!
        #include <QString>; // GOOD in Qt6!
        Q_PROPERTY(QString something ...)
        

        2. If I have a custom object like in this code :

        Q_PROPERTY(Camera activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
        

        I need to replace include "Camera.h" by Q_MOC_INCLUDE("Camera.h"). Is it correct ?

        No need to replace anything. A non-pointer has to be fully declared anyway so no change is necessary.

        3. If I have a pointer of a custom object

        Q_PROPERTY(Camera* activeCamera READ getActiveCamera NOTIFY activeCamerasChanged)
        

        Should I need to replace the Q_MOC_INCLUDE by a Q_DECLARE_OPAQUE_POINTER ?

        #ifndef OPAQUE_Camera
        #define OPAQUE_Camera
        Q_DECLARE_OPAQUE_POINTER(Camera*)
        #endif // OPAQUE_Camera
        

        No, it should be enough to use either #include (if you don't care about forward declarations) or Q_MOC_INCLUDE.

        4. If I have a QList of pointer

        Q_PROPERTY(QList<Camera*> cameras READ getCameras NOTIFY camerasChanged)
        

        Is the previous Q_DECLARE_OPAQUE_POINTER correct ?

        I don't know.

        5. If I have a Camera object and a QList<Camera*>, what should I use ?

        I don't understand the question, sorry.

        M Offline
        M Offline
        mipr
        wrote on 10 Jan 2023, 16:42 last edited by
        #3

        @sierdzio Thank you a lot for your answer !

        Your explaination on the opaque pointer is clear, I didn't have that notion before.

        With this knowledge, most of my questions are wrong, like the 5th.

        1 Reply Last reply
        0

        3/3

        10 Jan 2023, 16:42

        • Login

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