Results 1 to 7 of 7

Thread: Problem with QVariant and stream operators after upgrade

  1. #1
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    Hi all

    We've been using Qt 4.8.x for some time now. But now we want to upgrade to 5.5.1. Part of our application is using QGeoCoordinate. In 4.8, this was part of the QtMobility namespace. Of course, in 5.5.1 this is now part of the positioning module.

    Our application saves the QtMobility::QGeoCoordinate information to a file using a stream, and was able to read it back in. For this, we had these in our code to be able to use the stream and put the QGeoCoordinate in a QVariant.

    Qt Code:
    1. Q_DECLARE_METATYPE(QtMobility::QGeoCoordinate);
    2. qRegisterMetaType<QtMobility::QGeoCoordinate>("QtMobility::QGeoCoordinate");
    3. qRegisterMetaTypeStreamOperators<QtMobility::QGeoCoordinate>("QtMobility::QGeoCoordinate");
    To copy to clipboard, switch view to plain text mode 

    So now that QtMobility::QGeoCoordinate changed to the proper QGeoCoordinate, the loading of old streamed files results in:
    "Trying to construct an instance of an invalid type, type id: 127
    QVariant::load: unable to load type 42."
    And eventually a crash.

    Is there any way to solve this? I tried declaring the metatype and streaming metatype to something like
    Qt Code:
    1. qRegisterMetaType<QGeoCoordinate>("QtMobility::QGeoCoordinate");
    2. qRegisterMetaTypeStreamOperators<QGeoCoordinate>("QtMobility::QGeoCoordinate");
    To copy to clipboard, switch view to plain text mode 

    And other things, but nothing seems to work.


    Added after 1 5 minutes:


    Thinking about this, what about all custom classes with serialization that contain QGeoCoordinate? How will these be handled? I have lots of these, each declared and registered... How will the QVariant metatypes be handled?
    Last edited by Kwakkie; 2nd May 2016 at 14:10.

  2. #2
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    No ideas so far?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    Are you trying to deserialize a stream that has been serialized with the old type?

    Cheers,
    _

  4. #4
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    Yes, that is correct.

    I also tried adding the old type back in so I can deserialize it back and "convert" to the new type, but the mobility dll requires qt4core and qt4gui. So that doesn't work well if you're using qt5 as well.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    A shot in the dark here: would QMetaType::registerConverter() help? The documentation is a bit sparse, but it sounds like what you are trying to get to happen.

  6. The following user says thank you to d_stranz for this useful post:

    Kwakkie (4th May 2016)

  7. #6
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    Been reading up on registerConverter(). As far as I can see, you need to supply the conversion function. That makes a lot of sense of course, but it is basically registering a converter instead of e.g. in-lining it at the load code. It still means I'd need the original dll containing the type, the dll being unavailable as it's qt4.

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QVariant and stream operators after upgrade

    I don't know the details of how the type registration works but since this is done at runtime I doubt that even the old type would be registered with the old code.
    But in case it would, you could forward port it.

    However, my guess is that the typeIds are handed out linearly, so if the new type system doesn't have 126 types yet by the time your type is registered, it just won't get 127 as its id.

    You could, however, try registering the new type and then using QMetaType::registerTypedef() to make it an alias for 127.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    Kwakkie (4th May 2016)

Similar Threads

  1. Problem with QDataStream operators
    By d_stranz in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2014, 05:46
  2. Can´t use opengl after upgrade. Probably a linking problem?
    By roband915 in forum General Programming
    Replies: 1
    Last Post: 9th February 2011, 23:20
  3. Store QList<T> in QVariant and stream to QDataStream?
    By razvan.petru in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2009, 09:10
  4. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  5. QT 4.4.0 Upgrade QPainter Problem
    By ChrisReath in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 15:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.