[Qt-qml] Call C++ Slot from Workerscript.sendmessage
bea.lam at nokia.com
bea.lam at nokia.com
Tue Nov 2 02:13:37 CET 2010
Hi Mike,
On 01/11/2010, at 9:37 PM, ext Schmidt wrote:
>
>> Hi All,
>>
>>
>>
>> how do i call a slot of my c++-Programm from
>>
>> the WorkerScript .js file ?
>>
>>
>>
>> class MyClass {
>>
>> Q_OBJECT
>>
>> public slots:
>>
>> void work() { /* do something*/ }
>>
>> }
>>
>>
>>
>> MyClass is given to qml via setContextProperty("myclass", MyClass);
>>
Since the WorkerScript code is executed in a different thread, it is evaluated in a different context. So unlike an ordinary script file, it won't see any of the context properties of the QML object. I've created http://bugreports.qt.nokia.com/browse/QTBUG-14919 to make sure this gets documented.
I'd suggest you implement the threading with QThread in C++ instead. It is not possible in this case to pass the myclass object to the onMessage() handler to the invoke the function, since it's a QObject* and that cannot be passed to the WorkerScript.
regards,
Bea
More information about the Qt-qml
mailing list