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. QDatastream operate QPoint

QDatastream operate QPoint

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.0k 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.
  • S Offline
    S Offline
    samzhcs1
    wrote on last edited by
    #1

    Hello, I wrote a nibble code to test QDatastream, and set one break point at line 7.
    Environment is Qt5, QtCreator.
    But in QtCreator, when the program stopped at Line 7, in Local and Expression view, the tmp value is (0, 0), supposed to be (6,11).

    Dont' know why tmp is not (6,11).

    Many thanks in advance.

    1, QPoint pos(6,11);
    2, QPoint tmp;
    3, QByteArray datagram;

    4, QDataStream out(&datagram, QIODevice::ReadWrite);
    //out.setVersion(QDataStream::Qt_4_3);

    5, out << pos;
    6, out >> tmp;
    7, return 0;

    jsulmJ 1 Reply Last reply
    0
    • S samzhcs1

      Hello, I wrote a nibble code to test QDatastream, and set one break point at line 7.
      Environment is Qt5, QtCreator.
      But in QtCreator, when the program stopped at Line 7, in Local and Expression view, the tmp value is (0, 0), supposed to be (6,11).

      Dont' know why tmp is not (6,11).

      Many thanks in advance.

      1, QPoint pos(6,11);
      2, QPoint tmp;
      3, QByteArray datagram;

      4, QDataStream out(&datagram, QIODevice::ReadWrite);
      //out.setVersion(QDataStream::Qt_4_3);

      5, out << pos;
      6, out >> tmp;
      7, return 0;

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @samzhcs1 That's because your data stream is at the end after you write your point into it (you can check that calling http://doc.qt.io/qt-5/qdatastream.html#atEnd). If you then read then there is nothing to read: is like reading from a non empty file while being at the end of the file.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        This should work

        5, out << pos;
        6, out.device()->seek(0);
        7, out >> tmp;
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • S Offline
          S Offline
          samzhcs1
          wrote on last edited by
          #4

          Thanks, it works.

          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