[Qt-interest] QtScript: How to prevent default-constructed values calling methods from scripts with wrong types?
Wilhelm
wilhelm.meier at fh-kl.de
Sat Feb 12 21:07:24 CET 2011
Am 10.02.2011 15:44, schrieb Wilhelm:
> Hi all,
>
> this might be a dumb question but I can't find the right answer:
>
> Assume the following class Test:
>
> class Test : public QObject
> {
> ...
> Q_INVOKABLE Size foo(Size s);
> ...
> };
>
> which is exposed in a qtscript engine as variable "test".
>
> The class Size is a value-type declared as a Qt-Metatype.
see the complete example attached.
>
> All works well if I call Test::foo(Size) with a Size-Object. But if
> I call say foo("xxx"), the method gets called with a default-constructed
> Size-value. That's at least confusing and not want I want. I would like
> to have a runtime error here.
>
> How can I achieve that?
>
--
Wilhelm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.h
Type: text/x-chdr
Size: 411 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110212/107f33c6/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cc
Type: text/x-c++src
Size: 397 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110212/107f33c6/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: size.h
Type: text/x-chdr
Size: 692 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110212/107f33c6/attachment-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: size.cc
Type: text/x-c++src
Size: 738 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110212/107f33c6/attachment-0003.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cc
Type: text/x-c++src
Size: 983 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110212/107f33c6/attachment-0004.bin
More information about the Qt-interest-old
mailing list