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. working with Q_PROPERTY QPair and QList

working with Q_PROPERTY QPair and QList

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k 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.
  • B Offline
    B Offline
    bnogal
    wrote on last edited by
    #1

    working with Qt5.4.2

    i had to add support to a QVariant based serializer, so it can work with QList<QPair<T1, T2> > being T1 and T2 QVariant compatible. The data to serialize is defined as Q_PROPERTY of QObjects

    first I found out that Q_PROPERTY dont allow to write a comma on the type... as it recognize it as two parameters.

    So i did a workaround using a macro
    #define COMMA ,
    and defining the Q_PROPERTY as Q_PROPERTY(QPair<qreal COMMA qreal> ...

    but still, i got "Unable to handle unregistered datatype" when trying to read the property...

    so i had to register:

    qRegisterMetaType<QPair<qreal,qreal> >("QPair<qreal,qreal>");
    

    and got: "unable to save type/unable to load type", so i added
    qRegisterMetaTypeStreamOperators<QPair<qreal,qreal> >();

    And the QPair started to work, just qreal,qreal, of course...

    to make QList<QPair<qreal,qreal> > work... i had to register it again as:

    qRegisterMetaType<QList<QPair<qreal,qreal> > >("QList<QPair<qreal,qreal> >"); 
    qRegisterMetaTypeStreamOperators<QList<QPair<qreal,qreal> > >();
    

    from this point, everything works perfect, but just for QPair<qreal,qreal> and using an awful macro

    could it work without any workaround and registering types?

    i think that having moc step, it should be easy to remove the COMMA workaround.

    , the same for qRegisterMetaType....

    or i am overthinking it and there is a straight and easy way...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about:

      typedef QPair<qreal, qreal> YourClassName;
      typedef QList<YourClassName> YourClassNameList;
      

      Then you can use them more easily

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bnogal
        wrote on last edited by
        #3

        Hi, thx for the reply.

        yes, it is another option, and maybe i should jump to use structs straight. As you never know how it will need to grow

        but anyway, someone knows where is the moc compiler code?, i am trying to find it... but no success. Just to take a look

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          In the bin folder of your Qt Installation

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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