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_PROPERTY typedef
Forum Updated to NodeBB v4.3 + New Features

Q_PROPERTY typedef

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 397 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.
  • V Offline
    V Offline
    vinci
    wrote on last edited by
    #1

    The documentation for exposing C++ properties to QML says that:

    "Note: Do not use typedef or using for Q_PROPERTY types as these will confuse moc. This may make certain type comparisons fail."

    Yet types like QVariantMap are themself typedefs. E.g. QVariantMap is defined like this:

    typedef QMap<QString, QVariant> QVariantMap;
    

    I've just tried to use QVariantMap within the Q_PROPERTY macro and it worked fine? Is the documentation on this out of date? What exactly are "type comparisons" in this context?

    kshegunovK 1 Reply Last reply
    0
    • V vinci

      The documentation for exposing C++ properties to QML says that:

      "Note: Do not use typedef or using for Q_PROPERTY types as these will confuse moc. This may make certain type comparisons fail."

      Yet types like QVariantMap are themself typedefs. E.g. QVariantMap is defined like this:

      typedef QMap<QString, QVariant> QVariantMap;
      

      I've just tried to use QVariantMap within the Q_PROPERTY macro and it worked fine? Is the documentation on this out of date? What exactly are "type comparisons" in this context?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @vinci said in Q_PROPERTY typedef:

      Is the documentation on this out of date? What exactly are "type comparisons" in this context?

      Probably not out of date. I'd speculate it simply isn't telling the whole story. You can test this:
      Make your own typedef and do the Q_DECLARE_METATYPE and qRegisterMetatype stuff. Then try to use it as a type in the property. I suspect it should work. E.g. (split and reorder properly):

      namespace Test
      {
          Q_NAMESPACE
       
          enum TestEnum { MyValue };
          Q_ENUM_NS(TestEnum)
      }
      
      using TestEnum = Test::TestEnum;
      class Bar : public QObject {
          Q_OBJECT
          Q_PROPERTY(TestEnum enum READ enum WRITE setEnum NOTIFY enumChanged)
          // ... code
      };
      
      int main( ...)
      {
          qRegisterMetaType<TestEnum>("TestEnum");
      
          // Do the QML init and such
      }
      

      @vinci said in Q_PROPERTY typedef:

      Yet types like QVariantMap are themself typedefs. E.g. QVariantMap is defined like this:

      Variants are very special.

      What exactly are "type comparisons" in this context?

      As in whether TestEnum is convertible to int, or other enums, or can be streamed to a binary buffer, etc. The metatype reflection stuff basically.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • mzimmersM mzimmers referenced this topic on

      • Login

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