QT issues

U

uche

Hi Guys,

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


Code:
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 ...

Code:
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
Code:
 while (!(line =
reader->readLine()).isNull()) ..line.
Can anyone please help me ?
 
M

Michael DOUBEZ

uche a écrit :
[snip]
while (!(line = reader->readLine()).isNull()) //read lines from
[snip]
I keep getting a segmentation fault in the
Code:
 while (!(line =
reader->readLine()).isNull()) ..line.
Can anyone please help me ?


Yes. insert those lines:

assert(reader!=NULL);
while (!(line = reader->readLine()).isNull())
{
//...
assert(reader!=NULL);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top