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. Qt 5 -> Qt 6 Stream operator for QVariant
Forum Updated to NodeBB v4.3 + New Features

Qt 5 -> Qt 6 Stream operator for QVariant

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 572 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.
  • K Offline
    K Offline
    kazaak
    wrote on 23 Mar 2023, 06:21 last edited by kazaak
    #1

    I created a class that overloads the stream operator to read binary data. The implementation streams several variables to unpack a binary file like below:

    QDataStream &operator >>(QDataStream &stream,KItem &item) {
    
        stream >> item.itemTargetType;
        stream >> item.itemTarget;
        stream >> item.itemLabelName;
        stream >> item.itemLabelFont;
        stream >> item.itemLabelforegroundColor;
        stream >> item.itemLabelbackgroundColor;
        stream >> item.lockAspectRatio;
        stream >> item.itemImagePixmap;
        stream >> item.itemImageSize;
        stream >> item.datatagFilename;
    
        stream >> item.datatagTreeValues;
    
        return stream;
    }
    

    Everything worked fine in 5.15.2 but in 6.4.3 all the variables but the last one load. It's very nested along the lines of QHash<QString, QVariant> And the QVariant contains QVariantLists of QVariants, QPixmaps, QStringLists, and QDateTime. All these types are in QMetaType but they aren't loading and I get an empty QHash with this in the output:

    Trying to construct an instance of an invalid type, type id: 65
    Trying to construct an instance of an invalid type, type id: 16640
    Trying to construct an instance of an invalid type, type id: 16640
    Trying to construct an instance of an invalid type, type id: 18432
    Trying to construct an instance of an invalid type, type id: 3539043

    Does the nested QMetaTypes need to be registered as it's own type? If so, I don't know how to go about that since the QVariantList can contain a variable number and structure of QMetaTypes.

    C 1 Reply Last reply 23 Mar 2023, 07:29
    0
    • K kazaak
      23 Mar 2023, 06:21

      I created a class that overloads the stream operator to read binary data. The implementation streams several variables to unpack a binary file like below:

      QDataStream &operator >>(QDataStream &stream,KItem &item) {
      
          stream >> item.itemTargetType;
          stream >> item.itemTarget;
          stream >> item.itemLabelName;
          stream >> item.itemLabelFont;
          stream >> item.itemLabelforegroundColor;
          stream >> item.itemLabelbackgroundColor;
          stream >> item.lockAspectRatio;
          stream >> item.itemImagePixmap;
          stream >> item.itemImageSize;
          stream >> item.datatagFilename;
      
          stream >> item.datatagTreeValues;
      
          return stream;
      }
      

      Everything worked fine in 5.15.2 but in 6.4.3 all the variables but the last one load. It's very nested along the lines of QHash<QString, QVariant> And the QVariant contains QVariantLists of QVariants, QPixmaps, QStringLists, and QDateTime. All these types are in QMetaType but they aren't loading and I get an empty QHash with this in the output:

      Trying to construct an instance of an invalid type, type id: 65
      Trying to construct an instance of an invalid type, type id: 16640
      Trying to construct an instance of an invalid type, type id: 16640
      Trying to construct an instance of an invalid type, type id: 18432
      Trying to construct an instance of an invalid type, type id: 3539043

      Does the nested QMetaTypes need to be registered as it's own type? If so, I don't know how to go about that since the QVariantList can contain a variable number and structure of QMetaTypes.

      C Offline
      C Offline
      ChrisW67
      wrote on 23 Mar 2023, 07:29 last edited by
      #2

      @kazaak If the data you are reading was written by Qt 5.x then you may need to call QDataStream::setVersion() to allow the Qt6 implementations to adapt

      K 1 Reply Last reply 23 Mar 2023, 20:12
      3
      • C ChrisW67
        23 Mar 2023, 07:29

        @kazaak If the data you are reading was written by Qt 5.x then you may need to call QDataStream::setVersion() to allow the Qt6 implementations to adapt

        K Offline
        K Offline
        kazaak
        wrote on 23 Mar 2023, 20:12 last edited by
        #3

        @ChrisW67 Excellent! That was the issue and all bugs resolved. Quite the ctrl+F exercise for my entire project but I don't see another way around. Looks like support for previous stream versions will be there for a while. Thanks for the fast reply!

        1 Reply Last reply
        0

        1/3

        23 Mar 2023, 06:21

        • Login

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