[SOLVED] How to pass QDataStream between functions?



  • 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
    }
    @



  • What do you mean with 'not valid anymore' ?



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

    QDataStream::status() returns QDataStream::ReadCorruptData



  • 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).



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.