Label with text and number
Hey,
I have a Label and I want to put in a number and a text.
Code:
int a;
ui->label->setText(a "is the answer");
but this does not work, because qt can not see a there as a number. Maybe someone can help me?
Also when I want the label to say a over b I would write "a/b" and use
Code:
int a;
int b;
ui->label->setNum(a/b);
But obviously it calculates the result. I think it would also be possible if I could put Numbers in the setText function.
Re: Label with text and number
Look at the QString::arg() methods for formatting strings with extra arguments.
Code:
int a = 42;
QString formattedString
= QString( "%1 is the answer to life, the universe, and everything" ).
arg( a
);
Cracking open a C++ textbook would help you, too. You should realize that
Code:
ui->label->setText( a "some string" );
isn't correct C++ syntax.