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. Qt4 and Qt5 compatibility issue with QDatastream and QDateTime

Qt4 and Qt5 compatibility issue with QDatastream and QDateTime

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5qt4qdatastreamqstringqdatetime
2 Posts 1 Posters 559 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.
  • J Offline
    J Offline
    johnyang
    wrote on 1 Jun 2020, 01:29 last edited by
    #1

    I have some binary files that is created with an old application written in Qt4 by using QDatastream. Now I would like to read these files using a newer version of application written in Qt5. I am running into a weird scenario that only QDateTime variable can not be read correctly. It is always "invalid". Has there any major changes in how QDateTime gets serialized from Qt4 to QT5? All other primitive type of variables are all fine.

    Example1:

    QDateTime startTime;
    QString comment1; 
    
    void Read(QDataStream& in)
    {
         in >> startTime >> comment1;
    }
    

    The comment1 can be read correctly, but startTime is always invalid.

    Example2: (A even more weird situation)

    QDateTime startTime;
    QString comment1; 
    float     floatingvalue;
    
    void Read(QDataStream& in)
    {
         in >> comment1 >> startTime >> floatingvalue;
    }
    

    In this situation, both startTime and value can't be read correctly. However, if I put a quint16 variable after the Qstring variable, then "floatingvalue" can be read (even though startTime still gives wrong value). For example:

    void Read(QDataStream& in)
    {
         quint16 extra;
         in >> comment1 >> extra >> startTime >> floatingvalue;
    }
    

    I am wondering if QString is serialized differently as well?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johnyang
      wrote on 1 Jun 2020, 01:40 last edited by
      #2

      Now I realized I have to set QDataStream::setVersion to QDataStream::Qt_4_7. I think the problem is solved.

      1 Reply Last reply
      2

      1/2

      1 Jun 2020, 01:29

      • Login

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