Can I use QScriptEngine.toScriptValue with a QPointer to a QObject?

171 views Asked by At

The documentation on working with QtScript and converting back and forth between script values and C++ mentions that you can use QScriptEngine.toScriptValue with a QObject* type and have it work automatically, casting the object and returning a script reference accordingly. Does this same behavior hold with a QPointer<QObject> or do I have to create my own metatype? If so, does it also work for dealing with QPointers to a QObject subclass?

The main thing I'm interested in is whether or not the properties declared using Q_PROPERTY of a QObject subclass will automatically be brought into script if I call QScriptEngine.toScriptValue on a QPointer to a subclass instance instead of a regular pointer.

1

There are 1 answers

0
akbiggs On

I had to create my own script metatype to get a QPointer to get converted properly, it didn't work out of the box. However, the Qt documentation mentions that there's no point in specifying pointers as QPointers outside of initializaiton, since QPointers can be treated just like regular pointers, so this might have all been pointless.