-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.

6

1 Answer 1

0

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

Try this:

ui->label_1->setText(QString::number(ui->verticalSlider->value())); 
Sign up to request clarification or add additional context in comments.

5 Comments

@Creatronik with QString::number causes error ambiguous call to overloaded function?
@Creatronik qt5.4 with c++11?
No, std::to_string. QString::number works fine I have c++ 10.
@Creatronik But why would you want to use std::to_string(static_cast<int>(...))?
Because the compiler told me that the expression is ambiguous and that i would have to cast the datatype, like referred in a linked post in the comments of my initial question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.