Stored Type Question QStandardItemModel & QStandardItem
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.
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 ?
@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.
@MaestroMaus Nevermind; found it. Qt has a custom way of downcasting QVariant subclasses. I can just ask the type via a standard method.