This can be done passing the address of the combo box as pointer or reference.
Example:
void Customers::initComboBox(QComboBox *cb)
{
cb.clear();
for (int i = 0; i < m_itemCount; i++)
{
QString str = buildItemString(i);
cb->addItem(str);
}
}
Then call this from the constructors of the dialogs containing a customer combo box:
SomeDialog::SomeDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SomeDialog)
{
ui->setupUi(this);
Customers customers;
customers.initComboBox(ui->customerComboBox);
}
There is another solution by deriving a class from
QComboBox
that provides a setup function whith a parameter to your customer data and populates the box. Then change the dialog members to this type (using
QtCreator or manually in the dialog header files) and call the setup function in the dialog contructors passing the
Customers
class.