Answer the question
In order to leave comments, you need to log in
Why doesn't it read the file again?
Good afternoon. Such a problem: the function opens a file, creates a stream, reads a line from it and returns. The data is written to the TreeWidget. And so on until the end. The file is then closed.
I created a button in the application, which, firstly: clears the TreeWidget (checked that everything works correctly), and secondly, calls the same function above.
When the application is running, everything reads and writes to the TreeWidget normally. Then I open the file containing the data, change a couple of lines, save and close. I press the button and nothing happens. When I start the application again, all changes become noticeable. Help me please. Here is the code:
Function:
if(!m_stream.atEnd())
{
m_stream.setCodec("utf-8");
QString line = m_stream.readLine();
return line;
}
return "";
Answer the question
In order to leave comments, you need to log in
stream will read the file from the beginning only if it is re-opened or seek(0);
PS: Keeping the file open is bad practice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question