Nominate our 2022 Qt Champions!

Noob Qt question re: QStrings and lineEdit...

  • 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)


    delete ui;

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



  • move QString text3; outside on_EnterButton_clicked()

  • @Locry
    You can use append on textBrowser directly


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

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

  • 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...

Log in to reply