Created
December 4, 2011 06:06
-
-
Save diniremix/1429370 to your computer and use it in GitHub Desktop.
read file of text in Qt and show in QTextEdit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MainWindow::readfile(){ | |
| QString filename="test.txt"; | |
| QFile file(filename); | |
| if(!file.exists()){ | |
| qDebug() << "NO existe el archivo "<<filename; | |
| }else{ | |
| qDebug() << filename<<" encontrado..."; | |
| } | |
| QString line; | |
| ui->textEdit->clear(); | |
| if (file.open(QIODevice::ReadOnly | QIODevice::Text)){ | |
| QTextStream stream(&file); | |
| while (!stream.atEnd()){ | |
| line = stream.readLine(); | |
| ui->textEdit->setText(ui->textEdit->toPlainText()+line+"\n"); | |
| qDebug() << "linea: "<<line; | |
| } | |
| } | |
| file.close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, helped me too!