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. Stored Type Question QStandardItemModel & QStandardItem
QtWS25 Last Chance

Stored Type Question QStandardItemModel & QStandardItem

Scheduled Pinned Locked Moved General and Desktop
setdatasettextqstandarditemmoqstandarditem
4 Posts 2 Posters 1.6k Views
  • 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.
  • M Offline
    M Offline
    MaestroMaus
    wrote on last edited by MaestroMaus
    #1

    Hi, I have been trying to use the QStandardItemModel. In this model I have QStandardItem objects. These objects have QStrings and ints as data.

    While iterating through the QStandardItemModel I had trouble with the different data types. I was wondering; is there a dynamic way to find out which type of data is stored in the QStandardItems? Normally I would solve this by implementing the visitor pattern but in this case that would require me to subclass QStandardItem and I'd rather not do that.

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

      Hi and welcome to devnet,

      Do you mean that you can have both stored in different items ? Or both can found in the same item ?

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Do you mean that you can have both stored in different items ? Or both can found in the same item ?

        M Offline
        M Offline
        MaestroMaus
        wrote on last edited by MaestroMaus
        #3

        @SGaist Thanks for the welcome!

        QStandardItem takes any QVariant as a data. So it doesn't care whether I put QStrings or ints in it.

        I used this to have a collection of QStandardItems with ints in one column and QStrings in another. While iterating through these I need to check them for a certain value. I would like to do this without hardcording the value type for each column as this doesn't make the code flexible. Therefore; I am looking for some way to find out what data type a QVariant currently is.

        M 1 Reply Last reply
        0
        • M MaestroMaus

          @SGaist Thanks for the welcome!

          QStandardItem takes any QVariant as a data. So it doesn't care whether I put QStrings or ints in it.

          I used this to have a collection of QStandardItems with ints in one column and QStrings in another. While iterating through these I need to check them for a certain value. I would like to do this without hardcording the value type for each column as this doesn't make the code flexible. Therefore; I am looking for some way to find out what data type a QVariant currently is.

          M Offline
          M Offline
          MaestroMaus
          wrote on last edited by
          #4

          @MaestroMaus Nevermind; found it. Qt has a custom way of downcasting QVariant subclasses. I can just ask the type via a standard method.

          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