[Qt-interest] pass arguments to QObject subclass constructor from QtScript

Eric Miller ericm at sifteo.com
Fri May 20 03:16:12 CEST 2011


All -

I have a User class which is a subclass of QObject. The class has several constructors. In QtScript, I would like to be able to say:

	var user = new User("email at address.com");

OR

	var user = new User("email at address.com", someOtherArgument);

and so on, for three or four ways to make new User objects.

I'm seeing several places in the docs that discuss how to tie QObject-derived constructors to QtScript constructor functions, but they seem to gloss over binding constructor arguments from QtScript to the C++ constructors.

For example, http://doc.qt.nokia.com/4.7/qscriptengine.html#newQMetaObject shows how to specify a constructor that passes on one argument to the QObject constructor. Following this model, I've written a native User constructor function that has a switch statement for the various constructors of User, picking the right one based on the number of arguments and the types passed in from QtScript.

So that's fine, but it *seems* like the meta object system should know enough about the arguments coming in from QtScript and the constructors in my User object to match them up without my having to write a bunch of glue code between the two. Am I missing something or are switch statements the way to go?


thanks in advance,
E


More information about the Qt-interest-old mailing list