Results 1 to 1 of 1

Thread: QFile and QTextStream problems

  1. #1

    Default QFile and QTextStream problems

    Hi Guys,

    I declared a QFile* and QTextStream* pointers in a class called HistoricalInfo, then I instantiated them and the following function:


    Qt Code:
    1. int HistoricalInfo::Load(const QString & strFilename)
    2. {
    3.  
    4. file = new QFile(strFilename); //create new file, attached to a file name
    5.  
    6. reader = new QTextStream(file); //point reader to the file
    7.  
    8. if (!file->open(IO_ReadOnly | IO_Translate)) //test that file is opens sucessfully
    9. {
    10. errno = ENOENT; //exit if not opened correctly
    11. return 0;
    12. }
    13.  
    14. reader->setDevice(file); //set device
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 

    Then, I call following function (HistricalData_Read()) ), which was called by another function ...

    Qt Code:
    1. void HistoricalInfo::HistoricData_Read()
    2. {
    3. QString line;
    4. while (!(line = reader->readLine()).isNull()) //read lines from the file until there is no more data
    5. {
    6. if (line.isEmpty()) //if line is empty then go to the next line
    7. continue;
    8. if(line == "*") //if line is a star(delimiter) then ...
    9. { //we have found a whole data set then break
    10. break;
    11. }
    12. if(!Extractinfo(line, recSpeed)) //we can parse the line
    13. printf("error occured while extracting historical data\n"); //or error out!
    14. }
    15. LoadHistoricalinfo(); //load segement data into a list
    16. }
    To copy to clipboard, switch view to plain text mode 
    I keep getting a segmentation fault in the
    Qt Code:
    1. while (!(line = reader->readLine()).isNull()) ..line.
    To copy to clipboard, switch view to plain text mode 
    Can anyone please help me ?
    Last edited by marcel; 7th August 2008 at 03:55. Reason: missing [code] tags

Similar Threads

  1. Detecting errors with QTextStream and QFile
    By December in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 18:11
  2. QFile, QTextStream
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 12th January 2008, 19:40
  3. QTextStream + QFile issue
    By trueneo in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2007, 15:16
  4. QFile, QTextStream, seek()
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 29th September 2006, 15:07
  5. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.