[SOLVED]Connect qlineedit with horizontal slider
-
Hi,
I want to connect lineEdit with horizontal slider that will change values when the value in lineedit changes. (picture attached)!http://i60.tinypic.com/15nq3yd.png(http://i60.tinypic.com/15nq3yd.png)!I have tried this method but to no avail. I wonder if it's because the value inserted into lineedit is in QString format and the value in slider is in integer format?
cpp:
@
connect(ui->lineEdit_21,SIGNAL(textEdited(QString)),ui->horizontalSlider,SLOT(rag_valuechanged()));//in a separate function
ru_rag = ui->lineEdit_21->text();
int rag = ru_rag.toInt();
//separate function endsint RadioUserWindow::rag_valuechanged()
{
int r = rag;
ui->horizontalSlider->setValue(r);}
@error msg:
QObject::connect: No such slot QSlider::rag_valuechanged()
QObject::connect: (sender name: 'lineEdit_21')
QObject::connect: (receiver name: 'horizontalSlider')May I know what went wrong here?
-
@
connect(ui->lineEdit_21,SIGNAL(textEdited(QString)),ui->horizontalSlider,SLOT(rag_valuechanged()))
@The parameters for textEdited() and rag_valuechanged() should match. So it should be rag_valuechanged(QString) and then in that slot convert the QString to integer and set it to the horizontalSlider.
-
Agree with p3c0.
It would be like this.connect(ui->lineEdit_21,SIGNAL(textEdited(QString)),ui->horizontalSlider, SLOT (rag_valuechanged ( QString )));
-
i tried and i still get the same message, no such slot QSlider::rag_valuechanged(QString)
the slider did not change when the text is changed.
-
Have you applied changes into .h file according to rag_valuechanged(QString) slot??
If no, then I think you should define slot in .h file
void rag_valuechanged(QString) ;
-
i got it solved with the simpler way, right click and go to slot for lineedit and set the slider value from there without using the connect line. Thanks all.