Important: Please read the Qt Code of Conduct -

[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( | QFile::Text) ){
            QTextStream stream(&arquivo);
            QString linha;
            while( !stream.atEnd() ){
                linha = stream.readLine();


  • 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

    If that won't solve your problem take a look at

  • append() is working fine for me. Thank you.

Log in to reply