I am trying to read values from a text file using the Qt code given below.
int ReadFromFile(QString fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 1;
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine(1); //read one line at a time
QStringList lstLine = line.split(",");
}
file.close();
return 0;
}
The content of the text file is as follows:
1,0.173648178
2,0.342020143
3,0.5
4,0.64278761
5,0.766044443
6,0.866025404
However readLine always returns one character at a time but my intention is to read one line at a time and to split each line to get the individual comma seperated values.
Am I missing something basic here?
Yes. You're passing 1 for the maxlen parameter, which means to limit the line length to only 1 character. Try it without supplying anything for maxlen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With