PDA

View Full Version : comboBox signal question?



unix7777
21st March 2010, 19:17
i can't understand how to connect signal slots of comboBox.If it was just a pushButton everything is clear but comboBox consists of
different choices for example:

Cars
Bus
Truck

how to implement that different slot to be called if Cars is selected and different if Bus....?

viheaho
21st March 2010, 20:16
Maeby you don't need to... What if you connect QComboBox class signal currentIndexChanged ( const QString & text ) to slot where you use switch:


connect(combo,SIGNAL(QString &),this,SLOT(makesomething(QString &)));

void myClass::makesomething(QString selection){
switch(selection){

case...

}
}

zgulser
22nd March 2010, 07:15
There is no such distinction since you don't need to:).

You could emit a custom signal inside your "activated" signals slot in order to handle if the pressed item is a Bus.

unix7777
22nd March 2010, 15:53
What i do is:

connect(ui->comboBox, SIGNAL(currentIndexChanged()), this, SLOT(combochanged()));

void Rechnik::combochanged(int index)
{
switch (index) {
case 0:
select_dictionary1();
break;
case 1:
select_dictionary2();
break;
case 2:
select_dictionary3();
break;
}

it compiles without errors but nothing happens when i changed comboBox

squidge
22nd March 2010, 23:04
Check the output window - there will be an error there for you.

Also, check the documentation - currentIndexChanged() doesn't exist. It's currentIndexChanged(int)

unix7777
24th March 2010, 07:37
When i put some integer inside it underline it as error.
I suppose that inside must be the number of the selected item from comboBox i mean 0 for first, 1 for next etc.

squidge
24th March 2010, 07:53
Maybe you misunderstand, what I mean is this:

connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(combochanged(int)));

unix7777
24th March 2010, 10:10
it works, thanks a lot!!!!