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
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()),this,SLOT(result()));
}
void MainWindow::result()
{
int a=2;
int b=3 ;
int c= a+b;
ui->lineEdit->setText("c=");
ui->lineEdit->setText(s.setNum(c));
}
MainWindow::~MainWindow()
{
delete ui;
}
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).
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.