[SOLVED] A little bit confused about itemdata..
-
So basically i have a combobox with some items. The user can add-remove items.
Lets take an example, of these items referring to folder paths on our filesystem.
The item text would be the name of the folder.
the 1st data i want to keep (that i don't want to show to the user) is the fullpath.
and 2nd data, how many images the folder contains.
3rd data, how many videos the folder containsWhat i was doing until now is this:
@ ui->pictures_location_comboBox->setItemData(1, path);
ui->pictures_location_comboBox->setItemData(1, images_count, 12);
ui->pictures_location_comboBox->setItemData(1, video_count_count, 32);@and then of course take it with ->itemData
Which works absolutely well!But my friend asked me, why 32? And i searched this page, http://qt-project.org/doc/qt-5/qt.html
at section 'Qt::ItemDataRole' but i couldn't find it. I remember 32 was there.Anyways the point is not that.
What would you suggest? Use arrays instead?
They say if it ain't broke, don't fix it -
You should use the constant Qt::UserRole (Or Qt::UserRole+1 etc.) not the numeric value because than can, and has, changed between Qt versions.
http://qt-project.org/doc/qt-4.8/qt.html#ItemDataRole-enum
http://qt-project.org/doc/qt-5/qt.html#ItemDataRole-enum -
[quote author="ChrisW67" date="1413061118"]You should use the constant Qt::UserRole (Or Qt::UserRole+1 etc.) not the numeric value because than can, and has, changed between Qt versions.
http://qt-project.org/doc/qt-4.8/qt.html#ItemDataRole-enum
http://qt-project.org/doc/qt-5/qt.html#ItemDataRole-enum[/quote]O that's why..
so 32,33,34 and goes on? -
Hi,
It's Qt::UserRole that you should use as a base for your custom roles. Generally you would add a constant like MyRole = Qt::UserRole + 1 etc…
Hope it helps
-
[quote author="SGaist" date="1413062417"]Hi,
It's Qt::UserRole that you should use as a base for your custom roles. Generally you would add a constant like MyRole = Qt::UserRole + 1 etc…
Hope it helps[/quote]
Ok thank you both!