Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
Read line and store info?
davethedave last edited by
Hello, so I'm fiddling around with qfile and looked at some tutorials, but I can't see how I can read the file line by line to for example
store line 1 in username
and line 2 as password.
Currently doing this:
out << username << endl;
out << password << endl;
It outputs the details in the format:
I want to now store test in username and the other test in password, not sure if getline is what im looking for.
davethedave last edited by davethedave
I tried doing something like
QString line = out.readLine();
ui->lineusername->text() = line;
ui->linepassword->text() = line;
an array cannot be initialized with a parenthesized initializer
VRonin last edited by VRonin
out.device()->seek(0); // move back to the start of the file ui->lineusername->setText(out.readLine()); ui->linepassword->setText(out.readLine());
JonB last edited by JonB
In addition to what @VRonin has shown, if your
QLineEdits, you cannot assign via
text() = ...as you tried in yours, you'll want to use
setText(). [EDIT As @VRonin 's example now shows.]