Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with printing Details in txt File



  • hi in consol every thing in txt will be shown.
    now i want to show in textBrowser but will show me nothing
    @void MainWindow::on_pushButton_clicked()
    {
    QFile times("e:\time.txt");
    times.open(QIODevice::ReadOnly);
    QTextStream MyStream(&times);
    QString MyLine;

            do
    
    
            {
    
    
            MyLine  = MyStream.readLine();
            ui->textBrowser->setText(MyLine);
    
    
            }
    
    
             while(!MyLine.isNull());
    
        }
    

    @
    What must i do?


  • Lifetime Qt Champion

    Hi,

    @ui->textBrowser->setText(MyLine);@

    You replace the content of textBrowser at each iteration.

    On a side note, you don't check that the file opened successfully which is bad idea since it might not be found.

    Also with Qt you can use the unix notation on all platform i.e.
    @QFile times("e:/time.txt")@


Log in to reply