Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Noob Qt question re: QStrings and lineEdit...

    General and Desktop
    3
    5
    508
    Loading More Posts
    • 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.
    • Locry
      Locry last edited by A Former User

      This is my first foray into QTness...
      I'm simply trying to get USER input from-----------------------teexxt = ui->lineEdit->text();
      and to display it to------------------------------------------------------ui->textBrowser->setText(teexxt);
      Everything is working fine... but what I'm trying to achieve is that for every press of ----<void KimWidget::on_EnterButton_clicked()>
      the button... the text should add to the current text and not replace it.
      Currently everytime I press the button... the text in the textBrowser area is completely replaced by the new text.
      Here's the cpp file:
      #include "kimwidget.h"
      #include "ui_kimwidget.h"
      #include "QLineEdit.h"
      #include <QTextStream>

      KimWidget::KimWidget(QWidget *parent) : QWidget(parent), ui(new Ui::KimWidget)
      {
      ui->setupUi(this);

      }

      KimWidget::~KimWidget()
      {
      delete ui;
      }

      void KimWidget::on_EnterButton_clicked()
      {
      QString text2 = ui->lineEdit->text();
      QString text3;

      text3.append(text2);
      ui->textBrowser->setText(text3);
      ui->lineEdit->clear();
      

      }

      Ratzz 1 Reply Last reply Reply Quote 0
      • V
        vladstelmahovsky last edited by

        move QString text3; outside on_EnterButton_clicked()

        1 Reply Last reply Reply Quote 1
        • Ratzz
          Ratzz @Locry last edited by Ratzz

          @Locry
          You can use append on textBrowser directly

              ui->textBrowser->append(text2);
          

          Or if declare text3 as private variable as already suggested.
          If you append to text3 then text2 gets added in textBrowser.

          --Alles ist gut.

          1 Reply Last reply Reply Quote 1
          • Locry
            Locry last edited by

            Thanks guys!
            So i can either make text3 global, and/or append directly in the textBrowser... Wait i'll run some tests... Thanks again!

            1 Reply Last reply Reply Quote 0
            • Locry
              Locry last edited by

              Success!!!!! I just moved <QString text3;> outside as suggested. :)
              I forgot to mention... I tried declaring in the main.cpp file earlier... it didn't work.
              All 3 files are confusing. Not quite sure where to do what. :)

              Thanks again! Now I'll try the <ui->textBrowser->append(text2);> route... without declaring <QString text3;> outside...

              1 Reply Last reply Reply Quote 1
              • First post
                Last post