Hi,
Im pretty new at Qt and english isnt my main language but I will try to explain my doubt.

Im creating a program that reads a text file and print its last line in a textBox after you press a button (Stream). The thing is I want the textBox to update automatically after a new line is add in the text file, while I keep read the text file and dont close it.

For example, this is my text file at first time I read it:

Qt Code:
  1. Hello World.txt
  2.  
  3. 0
  4. 1
  5. 2
  6. 3
  7. 4
To copy to clipboard, switch view to plain text mode 

There should be printed ‘4’ in the textBox. (until here all OK)

But after the first read I add a new line in the text file with the number ‘5’, then the program should update automatically the textBox and add that new line.

I’ve made the same program a few months ago in C++ but now I want to put it in Qt

Qt Code:
  1. while (1)
  2. {
  3. if (logfile.is_open())
  4. {
  5. logfile.seekg(0, logfile.end);
  6. string line;
  7. while (true)
  8. {
  9. while (getline(logfile, line))
  10. {
  11. strncpy_s(send_data, line.c_str(), sizeof(send_data));
  12. send_data[sizeof(send_data)-1] = 0;
  13. ...
  14. }
  15. }
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

In Qt for now I have something like this

Qt Code:
  1. void PC::on_pushButtonStream_clicked()
  2. {
  3. QFile file(filename);
  4. if(!file.open(QIODevice::ReadOnly))
  5. QMessageBox::information(0,"info",file.errorString());
  6. if(file.isOpen()){
  7. // while(true) // << CRASH
  8. {
  9. while (!file.atEnd()) {
  10. QByteArray line = file.readLine();
  11. ui->textBrowserLog->setText(line);
  12. }
  13. // }
  14. }
  15. }
To copy to clipboard, switch view to plain text mode 

For now I have to click all time the Stream button to update the textBox

I’ve also tried to do a

Qt Code:
  1. while(file.isOpen())
To copy to clipboard, switch view to plain text mode 

but it crashes.

Thank you in advance.