PDA

View Full Version : QFile and QTextStream problems



uchennaanyanwu
7th August 2008, 02:44
Hi Guys,

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



int HistoricalInfo::Load(const QString & strFilename)
{

file = new QFile(strFilename); //create new file, attached to a file name

reader = new QTextStream(file); //point reader to the file

if (!file->open(IO_ReadOnly | IO_Translate)) //test that file is opens sucessfully
{
errno = ENOENT; //exit if not opened correctly
return 0;
}

reader->setDevice(file); //set device
...
}

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


void HistoricalInfo::HistoricData_Read()
{
QString line;
while (!(line = reader->readLine()).isNull()) //read lines from the file until there is no more data
{
if (line.isEmpty()) //if line is empty then go to the next line
continue;
if(line == "*") //if line is a star(delimiter) then ...
{ //we have found a whole data set then break
break;
}
if(!Extractinfo(line, recSpeed)) //we can parse the line
printf("error occured while extracting historical data\n"); //or error out!
}
LoadHistoricalinfo(); //load segement data into a list
}

I keep getting a segmentation fault in the
while (!(line = reader->readLine()).isNull()) ..line.

Can anyone please help me ?