Hi to all!
I've created combo box on some widget with:
m_pDatabaseSelector
=new QComboBox(this);
// creates new combo box Q_CHECK_PTR(m_pDatabaseSelector); // checks creation
m_pDatabaseSelector=new QComboBox(this); // creates new combo box
Q_CHECK_PTR(m_pDatabaseSelector); // checks creation
To copy to clipboard, switch view to plain text mode
and then fill it with:
m_pDatabaseSelector->addItem(strdbType); // adds db type to combo box
m_pDatabaseSelector->addItem("ODBC"); // adds db type to combo box
m_pDatabaseSelector->addItem("SQLite"); // adds db type to combo box
m_pDatabaseSelector->addItem(strdbType); // adds db type to combo box
m_pDatabaseSelector->addItem("ODBC"); // adds db type to combo box
m_pDatabaseSelector->addItem("SQLite"); // adds db type to combo box
To copy to clipboard, switch view to plain text mode
Combo box is shown and all item are in it as should be. Now, I've connected data selection signal with my slot:
connect(m_pDatabaseSelector,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(itemChanged(int))); // signal connector
connect(m_pDatabaseSelector,
SIGNAL(currentIndexChanged(int)),
this,
SLOT(itemChanged(int))); // signal connector
To copy to clipboard, switch view to plain text mode
and here the code for itemChanged(int):
void CDatabaseSettingsPage::itemChanged(int iSelectedIndex)
{
qDebug() << "iSelectedIndex:" << iSelectedIndex;
qDebug() << "m_pDatabaseSelector->itemData(iSelectedIndex).toString():" << m_pDatabaseSelector->itemData(iSelectedIndex).toString();
m_pAppSettings->updateRecord(databaseSettingKey,
strDatabaseTypeKey,
m_pDatabaseSelector->itemData(iSelectedIndex).toString());
}
void CDatabaseSettingsPage::itemChanged(int iSelectedIndex)
{
qDebug() << "iSelectedIndex:" << iSelectedIndex;
qDebug() << "m_pDatabaseSelector->itemData(iSelectedIndex).toString():" << m_pDatabaseSelector->itemData(iSelectedIndex).toString();
m_pAppSettings->updateRecord(databaseSettingKey,
strDatabaseTypeKey,
m_pDatabaseSelector->itemData(iSelectedIndex).toString());
}
To copy to clipboard, switch view to plain text mode
Well, itemData() returns empty string, iSelectedIndex is correclty setup. Why??
Bookmarks