[Qt-qml] Function in QScriptValue can only be called for a short time

Ville M. Vainio vivainio at gmail.com
Thu Feb 10 13:36:01 CET 2011


I am using QScriptValue to store a javascript function. I have a C++
method that stores it aside for later use:


void Deferred::onRes(const QScriptValue &v)
{
    m_res = v;

    //  m_res.call());  THIS WOULD WORK
}

- If I invoke call() as in the snippet above, in comments, the
function is called alright.
- If I invoke call() from the same QML method that called onRes, the
call works as well

- HOWEVER, if I invoke it even later (on some signal handler), the
function doesn't get called.

m_res.toString() shows the correct function body in all cases. It's as
if the link to script engine got broken somehow?

Any idea what "spoils" the QScriptValue in this fashion? I have tried
to ensure that nothing gets garbage collected, so I don't think that's
the cause.

-- 
Ville M. Vainio @@ Forum Nokia


More information about the Qt-qml mailing list