[Qt-interest] boost types in methods called from QtScript

Florian Vichot florian.vichot at diateam.net
Thu Feb 18 17:34:44 CET 2010


Hi RZ,

My guess is that, sadly, there is little you can do appart from changing
your prototype from "uint32" to "uint" or "quint32". This is because
when you call a method of your class from QtScript, Qt looks up the
method in its list of slots and methods marked Q_INVOKABLE, and tries to
find one with the same prototype. Problem is, when you have a method
with a prototype of :

SetStartParameters(uint32 a, uint16 b)

Qt knows nothing of "uint32" and "uint16", and thus when it does a
lookup, it doesn't know if the number it got from QtScript (here 'i')
can be converted into a 'uint32'. It knows it can convert to "quint16",
"quint32", "double", "uint", "int" and a bunch of others, but that's
because the conversion relationships are hardcoded into qvariant.cpp in
Qt's source code.

In your case, from Qt's point of view, "uint32" could be anything, even
a non POD type. So it doesn't take chances, and deems the types are
incompatible, hence the TypeError.

Florian


RZ a écrit :
> Hello all,
> 
> I managed to get my C++ (QObject derived) class invokable from QtScript. 
> So I can do in QtScript:
> 
> var myClass = new MyClass();
> 
> Unfortunately this C++ base class uses boost::uint32_t, boost::uint16_t, 
> ... (and then typedef boost::uint32_t uint32, ..). So a method inside my 
> class is:
> 
> SetStartParameters(uint32 a, uint16 b)
> 
> I can do
> 
> myClass.SetStartParameters(1, 2);
> 
> but whatever I try if I want to use var's instead like
> 
> var i = 2;
> myClass.SetStartParameters(1, i);
> 
> I always get a "TypeError" (because i is no uint16); interestingly it 
> works if I construct an overloaded method using Qt's types
> 
> SetStartParameters(quint32 a, quint16 b);
> 
> I tried things like Q_DECLARE_METATYPE(uint32), 
> qRegisterMetaType<uint32>("uint32"), qScriptRegisterMetaType (where I 
> don't know if I passed all parameters correctly).
> 
> Can anybody help what to do to get uint32 to work?
> 
> Thx,
> 
> RZ
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list