Casting a list as QVariant or QVariant List

妖精的绣舞 提交于 2019-12-05 00:47:53

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

If this is something you have to do frequently with varying types of lists 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 that when you call your function that takes in the QVariant list, you can just call

myFunction( toVariantList(myList) );

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!