Hi all,
I am trying to read in a tab-delimited text file. The code I wrote was first written using standard strings and infiles, and in the process of moving to Qt I am switching to the QFiles, QStrings, QTextStreams, and so on.
What I want to do is read in each line, parse out certain "keys" (or certain particular parts of the line, as defined by the tabs) and store these into QStrings.
Here is what I have:
QFile inFile(geneDesIn);
if ( inFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
QString temp2, temp3, temp6, temp15, line;
QTextStream stream( &inFile );
for (int counter = 3; counter < 3765; counter++) {
line = stream.readLine(); // line of text excluding '\n'
//we now have a line of text with a bunch of tabs inside it
//we want to parse it, tab by tab, and get out the fields we want: 2 3 6 15
temp2 = line.section('\t', 1,1);
temp3 = line.section('\t', 2,2);
temp6 = line.section('\t', 5,5);
temp15 = line.section('\t', 14,14);
//debug output to see the contents of the line
cout << "LINE: " << line.toStdString() << endl;
//line is now loaded
//do stuff with the temp strings
}
inFile.close();
}
However, I am having some issues.
Instead of reading in each line individually, it reads in the *entire* text file as one single line. It must not be detecting end-of-line characters or something.
Any ideas to get the code to read line by line, not everything at once?
Thank you.
Bookmarks