Qt4 clear() issue : Am I using it right?
-
Hi I am new to qt4 and I'm trying developing a framwork which includes certain topic(labels) to be added to the combo box. Adding topics to a combo box was a success but at ceratin point I need to Refresh the GUI and load the topics to their default state.
The code itself is called when a the following code is executed:
@ui_.refresh_topics_push_button->setIcon(QIcon::fromTheme("view-refresh")); connect(ui_.refresh_topics_push_button, SIGNAL(pressed()), this, SLOT(updateTopicList()));@
Through the function updateTopicList() ui_.topic->clear() is called. But on excecution of this code the control jumps to another function and executes it.
I also use the following snippet which contains the function which is accedentally executed. (onTopicChanged())
@connect(ui_.topics_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(onTopicChanged(int)));@Any help is appreciated
-
This is the correct behaviour. It is not accidental. Since combobox list is cleared, index changed. Hence slot topicChanged is called. You can do the following in your slot(onTopicChanged..)
void onTopicChanged(int a) {
if ( a== -1) return i.e don't do anything.}
-
Hi and welcome to devnet,
What do you mean by not working ? After calling clear are you repopulating the comboboxes ?
-
What is not working for you ?
- Is it the issue of combo box not cleared
- Is the issue of curentIndex slot is getting called ?
I have done simple program for you. Check it.
@ QComboBox box;
box.addItem("pthinks.com");
box.addItem("Dheeru");
box.addItem("qt-project");
box.addItem("Raj");box.show(); QPushButton buton("Clearme"); buton.show(); QObject::connect(&buton,SIGNAL(clicked()),&box,SLOT(clear())); QObject::connect(&box,SIGNAL(currentIndexChanged(int)),&w,SLOT(topicChanage(int)));void MainWindow::topicChanage(int va){
qDebug() << " Topic changed" << va << endl;
if (va == -1){
qDebug() << "List is cleared. Dont do anything" <<endl;
}
}@
Now if you give exact issue, we can help you.