QSA-interest Archive, April 2007
Crash with QVariant returning functions and QSA-1.1.5
Message 1 in thread
I have function that return QVariant with some data if input is valid
and invalid QVariant if input is invalid, like this:
//C++ code
QVariant MyClass::doStuff(const QVariant &a) {
if (isValidData(a)) {
//valid data
return processedData(a);
} else {
//invalid data
return QVariant();
}
}
Problem is if the data is invalid and the "empty" (invalid) variant is
returned to scripting, like with:
//QSA script code
x=doStuff(someInvalidData);
y=x.toString();
This results in:
ASSERT: "sh->iobj.isValid()" in ../kernel/quickobjects.cpp (1925)
ASSERT: "clss" in ../engine/qsobject.h (392)
Segmentation fault
Seems QSA does not handle invalid QVariants properly, though
operations like "if (x)" and "if (!x)" work fine on the invalid
QVariant (it evaluates as false). I think this should result in some
script error or exception, not in crash ...
What I was trying to return something that will evaluate to
"undefined" or something like that (and to "false" if used in "if"
cases). What should I use instead of empty variant in that case?
Martin Petricek
To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx
Message 2 in thread
BH wrote:
> I have function that return QVariant with some data if input is valid
> and invalid QVariant if input is invalid, like this:
...
> x=doStuff(someInvalidData);
> y=x.toString();
>
Hi,
The attached fix should fix the problem.
best regards,
Gunnar
==== //depot/quick/main/src/kernel/quickobjects.cpp#330 - d:\depot\quick\src\kernel\quickobjects.cpp ====
==== //depot/quick/main/src/kernel/quickobjects.cpp#330 - d:\depot\quick\src\kernel\quickobjects.cpp ====
@@ -1922,8 +1922,11 @@
QSObject QSVariantClass::invoke( QSObject * objPtr, const QSMember &mem ) const
{
QSVariantShared *sh = shared( objPtr );
- Q_ASSERT( sh->iobj.isValid() );
- return sh->iobj.invoke( mem, *env()->arguments() );
+
+ if (sh->iobj.isValid())
+ return sh->iobj.invoke( mem, *env()->arguments() );
+ else
+ return QSSharedClass::invoke(objPtr, mem);
}
/////////////////////////////////////////////////////////////////////////////