代码之家  ›  专栏  ›  技术社区  ›  cuteCAT

设计接受从QtScript传递的变量数参数的C++方法

  •  0
  • cuteCAT  · 技术社区  · 14 年前

    我正在学习QtScript,并编写了几个简单的示例。如果我将参数限制为简单类型,那么映射很简单。

    现在,我希望能够将数量可变的参数从QtScript传递给C++类,例如

    Myobject.add(1, 2, 3, "4444");
    Myobject.add( {first:1, second:2, third:333} );
    

    如何在C++实现中声明该方法?

    1 回复  |  直到 14 年前
        1
  •  1
  •   wilhelmtell    14 年前

    快速搜索建议您使用 QVariantList :

    void Myobject::add(QVariantList& l)
    {
        for( QVariantList::const_iterator i(l.begin()); i != l.end(); ++i ) {
            QVariant elem(*i);
            if( elem.canConvert<QVariantMap>() ) {
                // ...
            }
        }
    }
    

    不过,我现在还没有测试这个的工具。

    推荐文章