The above was lifted straight out of the documentation, QIODevice::Text is needed to convert the line end markers from '\r\n' and is probably the source of your problem.
Hmmm, still doesn't seem to work.
Can you post a bit more code with what you are actually doing in that loop?
Sorry, I probably should've done this in the first place :P
Here is the code for WRITING the file:
QMessageBox::information(this, tr
("Unable to open file"),
file.errorString());
return;
}
out << /*column headers*/ << \r\n;
for(int i = 0; i < nLines; i++)
{
out << /*column values*/ << \r\n;
}
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly)){
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QTextStream out(&file);
out << /*column headers*/ << \r\n;
for(int i = 0; i < nLines; i++)
{
out << /*column values*/ << \r\n;
}
To copy to clipboard, switch view to plain text mode
Here's a better look at the code for READING from the file:
QMessageBox::information(this, tr
("Unable to open file"),
file.errorString());
return;
}
//I used the approach in lines 12-15 to read the column headers
//because QTextStream::readLine() also made file.atEnd() return
//true, so the while loop was being skipped entirely
char firstLineIterator = 0;
while(firstLineIterator!= 10)
file.getChar(&firstLineIterator);
while(!file.atEnd())
{
//Store file name and direction (The first 2 values in each line in the
//file are strings, the rest are doubles)
in >> fileName >> direction;
//Store double values for the line
double inputArray[32];
for(int i=0; i<32; i++)
in >> inputArray[i];
/*store array values into spin boxes on the form*/
}
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
//I used the approach in lines 12-15 to read the column headers
//because QTextStream::readLine() also made file.atEnd() return
//true, so the while loop was being skipped entirely
char firstLineIterator = 0;
while(firstLineIterator!= 10)
file.getChar(&firstLineIterator);
QTextStream in(&file);
while(!file.atEnd())
{
//Store file name and direction (The first 2 values in each line in the
//file are strings, the rest are doubles)
QString fileName, direction;
in >> fileName >> direction;
//Store double values for the line
double inputArray[32];
for(int i=0; i<32; i++)
in >> inputArray[i];
/*store array values into spin boxes on the form*/
}
To copy to clipboard, switch view to plain text mode
I hope this is enough for you to get a better idea of what the problem could be
Bookmarks