-6

I have an int value out of a slider and want to write that value into a label with this expression

ui->label_1->setText(std::to_string(ui->verticalSlider->value()));

but i get this error:

ambiguous call to overloaded function

I think i have to typecast the value, but don't know how.

ui->label_1->setText(std::to_string(static_cast<int>(ui->verticalSlider->value())));

also didn't work.

Creatronik
  • 189
  • 3
  • 18
  • What is the signature of `value()`? Can you post the full error message instead of just that snippet? – Cory Kramer Jun 18 '15 at 13:39
  • 1
    are you using Visual C++? in that case check http://stackoverflow.com/questions/10664699 – fferri Jun 18 '15 at 13:39
  • 1
    possible duplicate of [Ambiguous call to overloaded function - std::to\_string](http://stackoverflow.com/questions/14617950/ambiguous-call-to-overloaded-function-stdto-string) – fferri Jun 18 '15 at 13:39
  • 1
    Please [edit](http://stackoverflow.com/posts/30916955/edit) your question with a [SSCCE](http://sscce.org). – NathanOliver Jun 18 '15 at 13:41
  • looks like Qt, try using QString::number, maybe it got better overloads (http://doc.qt.io/qt-5/qstring.html#number) – Hcorg Jun 18 '15 at 13:43
  • Yes i have Qt and yes QString::number worked, but what is the problem with the overloads? ui->label_1->setText(std::to_string(static_cast(ui->verticalSlider->value()))); doesn't work – Creatronik Jun 18 '15 at 13:48

1 Answers1

0

ui->label_1->setText needs QString and not std::to_string.

Try this:

ui->label_1->setText(QString::number(ui->verticalSlider->value()));
Protomen
  • 9,471
  • 9
  • 57
  • 124