Signal/Slots doesn't work with QSlider and QDoubleSpinBox
-
@HenrikSt. said:
hi
does connect(sliderHeight,xxx
return true
is the slot setValue called?U must define better "doesn't work" :)
-
@mrjj
QObject::connect: No such slot ResizeImageDialog::hightChanged(double) in ..\TextPad\PagesTextEdit.h:167
QObject::connect: Incompatible sender/receiver arguments
QSlider::valueChanged(int) --> QDoubleSpinBox::setValue(double)
yes: false -
@HenrikSt.
So what ever you are trying to connect, its not correct." Incompatible sender/receiver arguments"
I think it means
valueChanged(int) <<< INT to setValue(double)) << doublechange setValue to int
-
@HenrikSt.
Says it cant see the slot function
ResizeImageDialog::hightChangedcheck spelling etc.
-
@HenrikSt.
well check spelling and parameters. -
which objects are you trying to bind ?
show your connect statement after the change to int. -
Hi,
QDoubleSpinBox has no such slot, only setValue(double). Use the new Qt 5 notation for your connection, that will solve your problem.
i.e.
connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue);
-
See http://doc.qt.io/qt-5/signalsandslots-syntaxes.html#type-checking-and-implicit-type-conversions -- it uses exactly QSlider and QDoubleSpinBox in an example, and explains why it "doesn't work" with the old connection style.
-
@SGaist
Thank you, it works!But how can do that:
I have a chackbox. If the Checkbox is checked, the two spinboxes are Ratio. If i changed one slider, the other slider changed too. They both are Ratio to each other.
Do you understand?
-
Not really. Should both QDoubleSpinbox have the same value if that checkbox is checked?
-
Unfortunately not:
First version: "I have a chackbox. If the Checkbox is checked, the two spinboxes are Ratio. If i changed one slider, the other slider changed too. They both are Ratio to each other."Second version: "
The Checkbox is checked and
one slider is dragged. So than both checkboxes have the value from slider"In the first version you are talking about two spinboxes in the second version you are talking about two checkboxes. Sorry, but I'm lost...
And you did not answer my question whether both spinboxes (I assume you really mean spinboxes) should have the same value if one of them is changed while checkbox is checked. -
@jsulm
Yes, sorry. I mean SpinBoxes...Your Question:
Yes, both should have the same value when the ceckbox is checked:
if (m_keepRatioCheckBox->isChecked()) { connect(sliderHeight, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue); connect(sliderHeight, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue); connect(sliderWidth, &QSlider::valueChanged, m_hightSpinBox, &QDoubleSpinBox::setValue); connect(sliderWidth, &QSlider::valueChanged, m_widthSpinBox, &QDoubleSpinBox::setValue); }
This won't work..
-
What you could do: if, for example, sliderHeight is changed you do not set m_widthSpinBox directly, but instead you calculate the difference between m_hightSpinBox and its new value and add this difference (which can be negative) to m_widthSpinBox.
You will need your own slots for that. -
I did not test this code:
void MyClass::sliderHeightChanged(int value) { double diff = m_heightSpinBox->value - value; m_heightSpinBox->setValue(value); m_widthSpinBox->setValue(m_widthSpinBox->value + diff); } void MyClass::sliderWidthChanged(int value) { double diff = m_widthSpinBox->value - value; m_widthSpinBox->setValue(value); m_HeightSpinBox->setValue(m_heightSpinBox->value + diff); } if (m_keepRatioCheckBox->isChecked()) { connect(sliderHeight, &QSlider::valueChanged, this, &MyClass::sliderHeightChanged); connect(sliderWidth, &QSlider::valueChanged, this, &MyClass::sliderWidthChanged); }