0

Consider this code:

std::vector< std::vector<int> > v;
v.push_back( std::vector<int>( 1, 4 ) );
v.push_back( std::vector<int>( 1, 3 ) );
QComboBox box;
box.addItem( "", QVariant::fromValue<std::vector<int>>( v[0] ) );
box.addItem( "", QVariant::fromValue<std::vector<int>>( v[1] ) );
int pos = box.findData( QVariant::fromValue<std::vector<int>>(v[0]) );

pos is -1, when 0 was expected.

Manual search (for i to box.count()) is doable and works. As ( box.itemData( 0 ).value< std::vector<int> >() == v[0] ) surprisingly returns true! But findData is supposed to work too!

Note: Adding Q_DECLARE_METATYPE( std::vector<int> ); did not help

Edit 2016/05/03: Filled a Qt bug: https://bugreports.qt.io/browse/QTBUG-53152

jpo38
  • 20,821
  • 10
  • 70
  • 151

1 Answers1

4

QMetaType::registerComparators has to be called to have operator== be used instead of bitwise comparison.

Calling (once): QMetaType::registerComparators<std::vector<int>>(); makes findData work.

jpo38
  • 20,821
  • 10
  • 70
  • 151