How to foreach on all QComboBoxitems ?
-
I want to get all QStrings from a QComboBox, but do not know
how to manage the model stuff.
Started trial& error on the following code:@ foreach (QString str, myQComboBox )
{
qDebug() << _str;
}@or:
@ for( int i = 0;i < myQComboBox->count(); i++)
{
qDebug() << myQComboBox->itemText(i);
}
@both approaches are not OK
-
Hi,
What do you mean by not ok ?
-
sorry, not ok means a bunch of errors starting with :
/usr/include/QtCore/qglobal.h:2371: error: 'QComboBox*' is not a class, struct, or union type
typename T::const_iterator i, e;for this variant:
@ foreach (QString str, myQComboBox )
{
qDebug() << _str;
}
@the second (for loop) works.
-
foreach requires a container class (e.g. QList, QVector, etc.), QComboBox is not such a class
-
doesn't the model/ view framework of QComboBox provide such container and if so, how to access ?
-
From the "doc":http://qt-project.org/doc/qt-5/qcombobox.html
it seems there is no such method that returns a container.You might need to use the old school for loop and the count method of your combobox.Hope this helps.