Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Problem with QTextEdit object.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Problem with QTextEdit object.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    claudiogc
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckront
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        claudiogc
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved