Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved QTextStream crashes when reading a file

    General and Desktop
    2
    3
    344
    Loading More Posts
    • 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.
    • LeoC
      LeoC last edited by LeoC

      Hello,

      I have the following code:

          QFile fFile(strFile);
      
          if(!fFile.open(QIODevice::ReadOnly | QIODevice::Text))
              qDebug() << "can't read";
          else {
              qDebug() << "executed";
              QTextStream in(&fFile);
              qDebug() << "not executed";
              while(!in.atEnd()) {
                  qDebug() << in.readLine();
              }
              fFile.close();
          }
      

      Most of the time when the code is executed it crashes at the line QTextStream in(&fFile).
      The point is that I use the same code somewhere else to read other files and it is working absolutely fine. It is also very strange, that it works in very rare cases. There is definitively no problem with the file itself because there error occurs independent from what "strFile" contains (as long as it is a valid file).
      I really don't know what's going on here. The underlaying OS is Windows 7.

      Any ideas?

      1 Reply Last reply Reply Quote 0
      • V
        VRonin last edited by VRonin

        Could you post the stack trace of the crash? What version of Qt are you using? any chance fFile goes out of scope before entering the QTextStream in(&fFile); line?

        "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 Reply Quote 1
        • LeoC
          LeoC last edited by

          oooooh well :(

          Sorry guys, false alarm. I found the mistake somewhere else in the code. Wanted to write on a position in an array that wasn't available so far. Don't know how I made the connection to QTextStream.
          I didn't see the forest for the trees.

          Has been a long day, I should go home now. Sorry :)

          1 Reply Last reply Reply Quote 3
          • First post
            Last post