[SOLVED]Problem with QTextEdit object.
-
Hello, guys.
I'm trying to make a QTextEdit object show me a whole .txt file content, but it shows me only the last line! What am i doing wrong?
[code]void Ordenador::on_abrir_clicked(){
ui->texto->setOverwriteMode( false );
QFileDialog buscador;
QString caminho_arquivo = buscador.getOpenFileName(this, "Abrir arquivo.");if( !caminho_arquivo.isEmpty() ){ QFile arquivo(caminho_arquivo); if( arquivo.open(QIODevice::ReadWrite | QFile::Text) ){ QTextStream stream(&arquivo); QString linha; while( !stream.atEnd() ){ linha = stream.readLine(); ui->texto->setPlainText(linha); }
arquivo.close();
}
}
}[/code] -
with setPlainText() you actually overwrite any content in the textbox, so of course only the last line is written to the textbox.
you'll either have to save each line in a array, add it to your variable
@linha += stream.readLine();@or you could try the append() method of textbox
@ui->texto->append(stream.readLine());@If that won't solve your problem take a look at http://qt-project.org/doc/qt-4.8/qtextedit.html