Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Stored Type Question QStandardItemModel & QStandardItem

    General and Desktop
    setdata settext qstandarditemmo qstandarditem
    2
    4
    1199
    Loading More Posts
    • 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
      MaestroMaus last edited by MaestroMaus

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • M
          MaestroMaus @SGaist last edited by 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 1 Reply Last reply Reply Quote 0
          • M
            MaestroMaus @MaestroMaus last edited by

            @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 Reply Quote 0
            • First post
              Last post