[ACCEPTED]-Casting a list as QVariant or QVariant List-qvariant

Accepted answer
Score: 17

I've had to do this several times, and to 9 my knowledge the only way is to create a 8 new list.

If this is something you have to 7 do frequently with varying types of lists 6 you could do something a little fancier:

template <typename T>
QVariantList toVariantList( const QList<T> &list )
{
    QVariantList newList;
    foreach( const T &item, list )
        newList << item;

    return newList;
}

so 5 that when you call your function that takes 4 in the QVariant list, you can just call

myFunction( toVariantList(myList) );

Note 3 that the given function will only work for 2 types that can be implicitly converted to 1 QVariants.

More Related questions