Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习 QtScript 并写了几个简单的例子。如果我将参数限制为简单类型,则映射很简单。
我现在希望能够将可变数量的参数从 QtScript 传递给 C++ 类,例如
Myobject.add(1, 2, 3, "4444"); Myobject.add( {first:1, second:2, third:333} );
如何在 C++ 实现中声明方法?
快速搜索建议您使用QVariantList:
QVariantList
void Myobject::add(QVariantList& l) { for( QVariantList::const_iterator i(l.begin()); i != l.end(); ++i ) { QVariant elem(*i); if( elem.canConvert<QVariantMap>() ) { // ... } } }
不过,我现在没有工具来测试它。