I declared a QFile* and QTextStream* pointers in a class called
HistoricalInfo, then I instantiated them and the following function:
Expand|Select|Wrap|Line Numbers
- 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
- ....
- }
called by another function ...
Expand|Select|Wrap|Line Numbers
- 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
- }
Expand|Select|Wrap|Line Numbers
- while (!(line =
- reader->readLine()).isNull()) ..line.