-1

I have this little piece of code:

Qint32 value
Value = price * qty;
Qstring str;
Ui->lin->text(str.number(value));

But when I build it gives me the wrong values. The variables price and qty represent values from the database which I want to display in the results inside a qlineedit box.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Chris
  • 17
  • 3
    http://sscce.org/ – Jesper Juhl Sep 03 '22 at 23:03
  • 2
    Today I learned: SSCCE stands for Short, Self Contained, Correct Example :) For example: Including input and actual + expected output, etc. Welcome to SO, please take the [tour](https://stackoverflow.com/tour) and read [how to ask](https://stackoverflow.com/help/how-to-ask). – Christian Sep 03 '22 at 23:07
  • 1
    "`Ui->lin->text(str.number(value))`" - just do `Ui->lin->text(QString::number(value))`; the function is `static`, you don't need an object to call it. – Jesper Juhl Sep 03 '22 at 23:12
  • 3
    Welcome to Stack Overflow. Please read [ask] and [mre] and https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ and https://ericlippert.com/2014/03/05/how-to-debug-small-programs/. "It gives me the wrong values" does not adequately describe a problem. Make sure to show exactly how to use the code (we should be able to copy and paste your example code and see the exact problem directly, with as little intervention as possible); show exactly **what should happen**, and exactly **what does happen instead**. – Karl Knechtel Sep 03 '22 at 23:13
  • 1
    [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jesper Juhl Sep 03 '22 at 23:15

1 Answers1

0

First of all, C++ is case-sensitive, I mean, unless above is pseudo-code, almost everything is cased wrongly.

Try something like:

QLineEdit *lineEdit = ui->lin;

QInt32 value = price * qty;

lineEdit->setText(QString::number(value));

Note that the method name is setText(...) (instead of text).

Also, if your code gives you compile error(s), first read and handle those, or at least post them in your question.

bitmask
  • 32,434
  • 14
  • 99
  • 159
Top-Master
  • 7,611
  • 5
  • 39
  • 71