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. QTextStream crashes when reading a file
Forum Updated to NodeBB v4.3 + New Features

QTextStream crashes when reading a file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 620 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.
  • LeoCL Offline
    LeoCL Offline
    LeoC
    wrote on last edited by LeoC
    #1

    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
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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
      1
      • LeoCL Offline
        LeoCL Offline
        LeoC
        wrote on last edited by
        #3

        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
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved