Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] A little bit confused about itemdata..

[SOLVED] A little bit confused about itemdata..

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    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 contains

    What 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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon
        wrote on last edited by
        #3

        [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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            [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!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved