Thread: Qt apps - add to existing text

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    21

    Qt apps - add to existing text

    I have just started Qt widget programming. Part of my first program looks like this

    Code:
    void MainWindow::numberChanged(){
        int numOne=ui->numberOne->text().toInt();
        int numTwo=ui->numberTwo->text().toInt();
        int addition=numOne+numTwo;
        ui->textEdit->setText(QString::number(addition));
    }
    This void is triggered by a pushbutton. For the line in bold, I want it to ADD to what is already there instead of replacing each time the button is pressed (like the VB textbox1.text=textbox1.text+variable). Oh, and if I just have to read some manual, point one out please. Preferrably on the net.

    Not much of a program in itself, but would be useful to know for larger programs.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why not use +=?

    Qt 4.7: QString Class Reference

    (EDIT: I'm assuming textEdit is a QString, but I have to admit I don't know enough Qt to know whether it really is.)

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    21
    Thanks. textEdit is the name of the textfield being used (multiline instead of just one line). It was the default and I didn't bother changing it as its only a practise program for things like calculators, stack etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-29-2010, 09:07 PM
  2. appending text to existing text file
    By kpax in forum C Programming
    Replies: 8
    Last Post: 05-28-2008, 08:46 AM
  3. Windows apps verses Console apps
    By nano78 in forum Windows Programming
    Replies: 8
    Last Post: 09-22-2007, 03:41 AM
  4. WinSock // Existing Games
    By CPP-Null in forum C++ Programming
    Replies: 8
    Last Post: 05-24-2003, 12:23 PM
  5. is it easy to add a gui to existing console apps
    By blight2c in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 11:15 PM