Displaying Integers on QLabels?

后端 未结 3 2064
悲&欢浪女
悲&欢浪女 2021-01-07 02:45

Basically i\'m making a simple calculator program to understand the basics of C++ GUI however I get an error message leading to the line of code I have in the void Mai

相关标签:
3条回答
  • 2021-01-07 03:17

    You have to convert it:

    firstnumberx();
    secondnumberx();
    c = a+b;
    label->setText(QString::number(c));
    
    0 讨论(0)
  • 2021-01-07 03:27

    QLabel has setNum() methods taking int or double arguments:

    label->setNum(c);
    

    The setNum() methods format the supplied number and then set the text property with the formatted value. The documentation does not specify which locale is used for formatting, so you may wish to experiment.

    0 讨论(0)
  • 2021-01-07 03:35

    This should work..

    label -> setText(QString::number(c));
    

    If you need to add multiple number inside some string you can try below..

    label -> setText(QString("%1").arg(c));
    
    0 讨论(0)
提交回复
热议问题