Reputation: 11
I have a QPushButton, this button has a text on it, this text is a number. In a slot of another object i want to change number that displayed on button, but when i call
MyButton->setText(QString("%1").arg(Number));
or
QString tmp;
tmp.setNum(Number);
MyButton->setText(tmp);
text on button dosen't changes. But when i call
MyButton->setText("some random text");
it works fine. How i can change number that displaying on button?
Part of my code:
sortWindow::sortWindow(QWidget *parrent)
{
...
MyButton = new QPushButton;
QString tmp(QString("%1").arg(Number));
MyButton.setText(tmp);
...
}
and
void sortWindow::workOnSignal(int index)
{
...
if (something)
{
...
QString tmp;
tmp.setNum(Number);
MyButton->setText(tmp);
...
}
Upvotes: 1
Views: 528
Reputation: 1585
Type of Number
must be int
. So it will work properly.
#include <QApplication>
#include <QPushButton>
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QPushButton *pd = new QPushButton;
pd->setText(QString("%1").arg(1234));
pd->show();
return app.exec();
}
Upvotes: 2