Results 1 to 3 of 3

Thread: To Display output like c=5 in qt creator within same line edit.

  1. #1
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default To Display output like c=5 in qt creator within same line edit.

    i want to display output line c=5 in sam line edit. but m only getting 5 .

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. connect(ui->pushButton, SIGNAL(clicked()),this,SLOT(result()));
    10. }
    11.  
    12. void MainWindow::result()
    13. {
    14. int a=2;
    15. int b=3 ;
    16. int c= a+b;
    17. QString s="";
    18. ui->lineEdit->setText("c=");
    19. ui->lineEdit->setText(s.setNum(c));
    20.  
    21.  
    22. }
    23.  
    24. MainWindow::~MainWindow()
    25. {
    26. delete ui;
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: To Display output like c=5 in qt creator within same line edit.

    Look at arg() member function in QString and it's overloads, and construct a QString with what you need and set that to display in the label (or lineEdit).

  3. The following user says thank you to Zlatomir for this useful post:

    nawaz (30th January 2013)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: To Display output like c=5 in qt creator within same line edit.

    Every time you call setText(), it completely replaces the current text in the line edit. So your second call to setText() erases the "c=" and replaces it with "5". What Zlatomir is telling you is to look at the QString::arg() methods, and use them to build a QString that contains both "c=" and the result of the calculation, then call setText() once with that formatted string.

  5. The following user says thank you to d_stranz for this useful post:

    nawaz (30th January 2013)

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Replies: 3
    Last Post: 26th August 2010, 08:57
  3. how to access LINE EDIT'S value
    By BalaQT in forum Qt Programming
    Replies: 8
    Last Post: 20th August 2009, 10:58
  4. mask line edit
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 3rd July 2007, 10:27
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.