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. Stream operator in QT 5.x

Stream operator in QT 5.x

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.7k 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.
  • U Offline
    U Offline
    uszatan
    wrote on last edited by
    #1

    Hi,
    I need some help with new Qt version..

    I'm trying to port my application, developped originally in Qt 4.8.5 to new version. I downloaded and installed most recent version of Qt ( 5.2.1 ), also all required tools incl Mingw 4.8.. and in general everything seems to be OK - i had to make a few changes - mostly replace some deprecated functions, the project compiled properly BUT:
    in debug mode all the stream operators ( <<, >> ) seems not to be working:

    • cant's display any qDebug output when using construction:
      @qDebug() << "Some text"; @

    while

    @qDebug("Some other text") @

    works fine

    • in debug mode I also notice that my functions which uses QDataStream are not working - no data is being written to output files. When compiling in release mode - some data is written to a file.

    I tested this on 3 PC's incl. 1 fresh virtual machine - always the same issue.
    Here is a sample code - which stopped working:

    @ if( m_ProjectFile.isOpen() )
    {
    m_ProjectFile.close();
    }

    QDataStream temp_FileStream;
    m_ProjectFile.open( QIODevice::WriteOnly );
    m_ProjectFile.seek(0);
    
    //temp_FileStream.setVersion(QDataStream::Qt_5_0);
    temp_FileStream.setDevice( &m_ProjectFile );
    
    temp_FileStream << m_ProjectDetails.m_ProjectName;
    temp_FileStream << m_ProjectDetails.m_ProjectVersion;
    temp_FileStream << m_ProjectDetails.m_ProjectTimestamp;
    temp_FileStream << m_ProjectDetails.m_ElementsCount;
    
    for( int i=0; i<m_ProjectDetails.m_ElementsCount; i++ )
    {
        m_FileStream << m_ProjectDetails.m_SequencesList.at(i).m_SequenceName;
        m_FileStream << m_ProjectDetails.m_SequencesList.at(i).m_SequencePath;
    }
    m_ProjectFile.close();@
    

    Thanks in advance for all the suggestions,
    Piotr

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Here is my small example that works fine. The difference is that I don't use for loop and I use Linux. A file test.txt is created and contains all data that I've sent.

      Try to run small app in debugger and check temp_FileStream.q_status.
      Is there any output in a console while this code is running?

      @
      #include <QDataStream>
      #include <QFile>
      #include <QDebug>

      struct ProjectDetails
      {
      QString m_ProjectName;
      QString m_ProjectVersion;
      int m_ProjectTimestamp;
      int m_ElementsCount;
      };

      int main(int, char **)
      {
      QFile m_ProjectFile("test.txt");

      QDataStream temp_FileStream;
      m_ProjectFile.open( QIODevice::WriteOnly );
      m_ProjectFile.seek(0);
      
      qDebug() << __FILE__ << ":" << __LINE__;
      
      //temp_FileStream.setVersion(QDataStream::Qt_5_0);
      temp_FileStream.setDevice( &m_ProjectFile );
      
      ProjectDetails m_ProjectDetails = {
          "Test hello world.",
          "1.0.0",
          111111,
          25
      };
      
      temp_FileStream << m_ProjectDetails.m_ProjectName;
      temp_FileStream << m_ProjectDetails.m_ProjectVersion;
      temp_FileStream << m_ProjectDetails.m_ProjectTimestamp;
      temp_FileStream << m_ProjectDetails.m_ElementsCount;
      
      m_ProjectFile.close();
      
      return 0;
      

      }
      @

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uszatan
        wrote on last edited by
        #3

        Hi,
        Thanks for reply, but it is not a case.
        I have no issues with QT 5.x in Linux, neither in windows while using visual c++ compiler. This problem appears only when using QT built with mingw , with the mingw compiler shipped with this version (4.8). Unfortuantelly it has to buildwith this compiler...

        Regards,
        Piotr

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Have you tried to run it under debugger using "broken" Qt build ?
          What status of the stream?
          Do you see any output in a console?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            I can assure you that stream operators, a standard part of C++ and nothing specifically to do with Qt, work just fine with the bundled GCC.

            The most likely cause of the failure of your code to do what you expect with the QDataStream is that the file you are opeining is either not opening, in a non-writable location and/or not where you think it is at run time. Since you do not check that the file actually opened (open() has a return value) you get no warning when it fails and have no reason to check the errorString().

            1 Reply Last reply
            0
            • U Offline
              U Offline
              uszatan
              wrote on last edited by
              #6

              Hi,
              Acctually i found a reason for that strange behaviour - so because my code is using external DLL - compiled in bcc - i have to use CXX flag:

              -fshort-enums

              i'm not sure what is the link between that flag and the QDataStream / QDebug classes - but it obviously is.
              Now i need to find a way to make it work :)

              Thanks,
              Piotr

              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