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. Noob Qt question re: QStrings and lineEdit...
QtWS25 Last Chance

Noob Qt question re: QStrings and lineEdit...

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 642 Views
  • 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.
  • LocryL Offline
    LocryL Offline
    Locry
    wrote on last edited by A Former User
    #1

    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();
    

    }

    RatzzR 1 Reply Last reply
    0
    • V Offline
      V Offline
      vladstelmahovsky
      wrote on last edited by
      #2

      move QString text3; outside on_EnterButton_clicked()

      1 Reply Last reply
      1
      • LocryL Locry

        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();
        

        }

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by Ratzz
        #3

        @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
        1
        • LocryL Offline
          LocryL Offline
          Locry
          wrote on last edited by
          #4

          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
          0
          • LocryL Offline
            LocryL Offline
            Locry
            wrote on last edited by
            #5

            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
            1

            • Login

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