
Originally Posted by
coderbob
I am at a loss as to what to say wysota. The code cannot become much simpler
Of course it can become much simpler. You only need to show three statements in three different situations and it doesn't require a bunch of files and having to click some area in a window.
If this is true then please explain why when a class that inherits QObject is passed by defined type you cannot access any properties in QML/JS
That's simple - because the scripting environment doesn't know your QObject subclass is really a QObject subclass so it doesn't try to extract the proper type from QVariant. This is a deficiency of QScriptEngine or QVariant, I guess.
it will be cast as a QVariant with no way to access its properties in QML/JS.
There is a trivial way to access your properties. Simply export a method that will perform the conversion in C++. Something like:
if(!v.canConvert<QObject*>()) return 0;
QObject *o
= v.
convert<QObject
*>
();
return qobject_cast<Object1*>(o);
}
Object1* argToObject1(QVariant v) {
if(!v.canConvert<QObject*>()) return 0;
QObject *o = v.convert<QObject*>();
return qobject_cast<Object1*>(o);
}
To copy to clipboard, switch view to plain text mode
The SAME EXACT OBJECT is being passed to the function and should be casted the same.
Well... "it depends". According to javascript you can never rely on the type of arguments passed to a function, it's not a strongly-typed language.
This is the whole reason behind inheriting QObject and the meta system.
And that's the only thing that makes this problematic.
The output is as clear as day, I am not sure how this is not making sense to you.
It's not that it doesn't make sense - I can analyze code and understand it but if you are providing a potential bug sample, you shouldn't force anyone to have to analyze your code for half an hour each time like I had to be doing from the very beginning of this thread. In my opinion if something is larger than 30 LOC, it's not a test-case anymore.
Bookmarks