0

I am learning QtScript and wrote several trivial examples. The mapping is straightforward if I limit arguments to simple types.

I now want to be able to pass variable number of arguments from QtScript to the C++ class, such as

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

How to declare the method in the C++ implement?

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
cuteCAT
  • 2,251
  • 4
  • 25
  • 30

1 Answers1

1

A quick search suggests you use QVariantList:

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

I don't have the tools to test this right now though.

wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
  • This would add an overload for calls with one array argument while the OP seems to look for a way to pass a variable number of arguments to one function (for which it looks like there is no convenience support?). – Georg Fritzsche Nov 12 '10 at 20:58