N
N
Nicky232020-04-17 14:55:36
Qt
Nicky23, 2020-04-17 14:55:36

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 "";

m_stream is created in another function, it is also attached to the file there.
As I said above, after the completion of this function, I close the file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-04-17
@Nicky23

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 question

Ask a Question

731 491 924 answers to any question