I have a problem with QCombo's findData function which is always returning -1 value.
---SerialPortPage.cpp---
//I have declared metatype of custom StopBitsType.
Q_DECLARE_METATYPE(StopBitsType)
...
//then add some items to QComboBox
stopCombo->addItem("1", qVariantFromValue(STOP_1));
#ifdef _TTY_WIN_
stopCombo->addItem("1.5", qVariantFromValue(STOP_1_5));
#endif /*_TTY_WIN_*/
stopCombo->addItem("2", qVariantFromValue(STOP_2));
...
//this is working very well, returning value of proper StopBitsType
stopCombo->itemData(stopCombo->currentIndex()).value<StopBitsType>()
...
//however findData is always returning -1...
stopCombo->findData(qVariantFromValue(STOP_2)) //printf or something
//I have declared metatype of custom StopBitsType.
Q_DECLARE_METATYPE(StopBitsType)
...
//then add some items to QComboBox
stopCombo->addItem("1", qVariantFromValue(STOP_1));
#ifdef _TTY_WIN_
stopCombo->addItem("1.5", qVariantFromValue(STOP_1_5));
#endif /*_TTY_WIN_*/
stopCombo->addItem("2", qVariantFromValue(STOP_2));
...
//this is working very well, returning value of proper StopBitsType
stopCombo->itemData(stopCombo->currentIndex()).value<StopBitsType>()
...
//however findData is always returning -1...
stopCombo->findData(qVariantFromValue(STOP_2)) //printf or something
To copy to clipboard, switch view to plain text mode
Am I doing something wrong :/ ? Have you ever use this function ?
I didn't find any examples or information except short description in the documentation.
int QComboBox::findData ( const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const
Returns the index of the item containing the given data for the given role; otherwise returns -1.
The flags specify how the items in the combobox are searched.
The StopBitsType is defined as:
---qextserialbase.h---
typedef enum _StopBitsType {
STOP_1,
STOP_1_5, //WINDOWS ONLY
STOP_2
} StopBitsType;
typedef enum _StopBitsType {
STOP_1,
STOP_1_5, //WINDOWS ONLY
STOP_2
} StopBitsType;
To copy to clipboard, switch view to plain text mode
Bookmarks