Update a ComboBox after opening QDialog

0

How do I update a ComboBox after opening a QDialog?

The code below does not update if you have made an update to db. I have to close the application and open it to show the new data:

Dialog::Dialog(){
  carregar_comboBox();
}

void Dialog::carrega_comboBox(){
    qry..
     while..
     ui->comboBox->addItem(qry.value(0).toString());
} 
    
asked by anonymous 29.03.2014 / 19:08

1 answer

1

By all means, you need the carregar_comboBox() function to always be called before the dialog is displayed on the screen. A simple solution is to re-implement the show() function by overwriting QDialog::show() :

class SeuDialog : public QDialog {

    \* ... *\

public:

     // Sempre que alguém chamar essa função para mostrar a dialog...
     void show() {
         carregar_comboBox(); // Primeiro carregue sua ComboBox
         QDialog::show();     // Somente depois mostre de fato a dialog
     }
}

It would also be interesting to implement showMaximized() similarly so that the behavior is consistent.

    
26.04.2014 / 02:50