I have a file which I would like to read again and again, to update a paramter in my code. but using QTextStream only reads the value once, and reads out 0 after that every time.
This is basically my code:
int main(){
QString data;
QFile Status;
Status.setFileName("/home/user/status");
Status.open(QIODevice::ReadOnly);
QTextStream in(&Status);
While(1){
usleep(100);
data = in.readLine();
cout << "This is the status: " << data.toInt();
}
return 0;
}
Problem is that it reads the “status” file correctly the fist time, but after that, it reads out “0”…Any thoughts of how I can read out this file again and again.
In additional info, my thought is to change the data of the file to update my app status, which is a number (int) between 0 and 100.
Thank you for any help, it is appreciated.. 🙂
Your code doesnt make sense. If you have successfully opened the file, then nobody will be able to open it for writing.
You can modify the loop :
The if is a naive attempt to wait when if the file is opened by another program.