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. [SOLVED] How to pass QDataStream between functions?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to pass QDataStream between functions?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.8k Views 1 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.
  • S Offline
    S Offline
    soroush
    wrote on last edited by
    #1

    Hi

    I have two functions, A and B. An instance of QDataStream is created in A and it should be passed to B so B can write some data on it. After passing a stream by reference, it seems that it's not valid anymore.

    What do you suggest?

    @
    void A() {
    QDataStream x;
    // ...
    B(x);
    }

    void B (QDataStream& d)
    {
    // Do something with d
    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on last edited by
      #2

      What do you mean with 'not valid anymore' ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soroush
        wrote on last edited by
        #3

        [quote author="Thomas Zander" date="1360964028"]What do you mean with 'not valid anymore' ?[/quote]

        QDataStream::status() returns QDataStream::ReadCorruptData

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          That has nothing to do with passing QDataStream as a reference. QDataStream doesn't even know how it's passed or that it has been passed.
          You have a problem in your actual data streaming operations (or the file you're trying to read really is corrupt).

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Indeed. A QDataStream can be passed by reference just fine. However, you should probably avoid storing that reference and then re-using it later on.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              soroush
              wrote on last edited by
              #6

              Oops

              An incorrect counter in loop caused to seek out of file. This was a really disappointing effort for me :( I'm struggling to solve this for a couple of days, but I even can't see such a simple bug.

              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