PDA

View Full Version : QComboBox and QSlider same signal



johan07
16th November 2015, 09:24
Hi,
i have QComboBox when i select item they send signal to an function to do something


liste = new QComboBox();
connect(liste , SIGNAL(currentIndexChanged(int)),this,SLOT(handleS electionChanged(int)));
void MainWindow::handleSelectionChanged(int i)
{

emit display(i);
connect(this, SIGNAL(display(int)),myapp, SLOT(display(int))) ;
connect(liste, SIGNAL(display(int)),myapp, SLOT(display(int))) ;

}

and that's work
in the other hand i have QSlider


m_slider = new QSlider(Qt::Horizontal, page_13);
m_slider->setGeometry(10, 60, 150, 20);
m_slider->setMinimum(0);
m_slider->setMaximum(5);
m_slider->setSingleStep(0.01);
connect(m_slider, SIGNAL(valueChanged(int)),mQOgreWidget, SLOT(display(int))) ;


i want change strategy , where when i select item from the QComboBox it does not send signal to display, but save the index of the item( save i)
and the QSlider send signal to another function that take into account the index i of the item and the value of the slider

is there somone have an idea how i do it ?

anda_skoa
16th November 2015, 10:32
and that's work

Strange, it should not.
QComboBox doesn't have a signal "display(int)"

It also creates new connections everytime the slot is called, doubtful that this is wanted



i want change strategy , where when i select item from the QComboBox it does not send signal to display, but save the index of the item( save i)
and the QSlider send signal to another function that take into account the index i of the item and the value of the slider

is there somone have an idea how i do it ?

Store the integer from the combobox in a place that the slot connected to the slider has access to.
If slider and combobox are members of the same class and the slot is also implemented in that class, you can simply access QComboBox::currentIndex() in the slot.

Cheers,
_

johan07
16th November 2015, 12:37
Store the integer from the combobox in a place that the slot connected to the slider has access to.
If slider and combobox are members of the same class and the slot is also implemented in that class, you can simply access QComboBox::currentIndex() in the slot.

sorry i did not understand

anda_skoa
16th November 2015, 13:53
Add a member variable to whatever class mQOgreWidget is of.
Add a slot to that class that takes and int and stores it in that variable.
Connect the combobox to that slot.

The slot in that class that handles the slider value, then also has access to the current index of the combobox.

Unless you need something different, but then it would be nice to let us know.

Cheers,
_