| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi. I'm trying to add script support to existing Qt app. Basically I want
to give end-user way to execute own script files. It works as expected,
however I have one problem. User can create some script like:
while (1)
{
}
And app will freeze forever. Yes, I can execute scripts in non-GUI thread
and there will be no app freeze. But I will get "script" thread freeze...
Any way to set some kind of time-limit to script execution? Or maybe there
is some correct way to terminate execution from another thread?
I can call QThread::terminate() for script thread, but as for me, this
isn't correct solution.
Thanks
--
[ signature omitted ]
Attachment:
signature.asc
Description: Digital signature
On Monday 07 January 2008 21:06:32 Dmitry Nezhevenko wrote:
> Hi. I'm trying to add script support to existing Qt app. Basically I want
> to give end-user way to execute own script files. It works as expected,
> however I have one problem. User can create some script like:
>
> while (1)
> {
> }
>
> And app will freeze forever. Yes, I can execute scripts in non-GUI thread
> and there will be no app freeze. But I will get "script" thread freeze...
>
> Any way to set some kind of time-limit to script execution? Or maybe there
> is some correct way to terminate execution from another thread?
Since qt4.4 you can use a QScriptEngineAgent and add a timer in its
functionEntry/functionExit calls. If your max timeout is reached, throw an
exception: QStciptContext::throwError ("endless loop ...");
There is no such ability in qt < 4.4 though.
Frank
--
[ signature omitted ]
Frank Hemer wrote:
> Since qt4.4 you can use a QScriptEngineAgent and add a timer in its
> functionEntry/functionExit calls. If your max timeout is reached, throw an
> exception: QStciptContext::throwError ("endless loop ...");
>
If the event loop is blocked by the script executing, will your QTimer
ever emit timeout()? Or does QtScript not allow scripts to starve the
event loop like QSA did?
--Dave
--
[ signature omitted ]
On Tuesday 08 January 2008 14:59:28 Dave Smith wrote:
> Frank Hemer wrote:
> > Since qt4.4 you can use a QScriptEngineAgent and add a timer in its
> > functionEntry/functionExit calls. If your max timeout is reached, throw
> > an exception: QStciptContext::throwError ("endless loop ...");
>
> If the event loop is blocked by the script executing, will your QTimer
> ever emit timeout()? Or does QtScript not allow scripts to starve the
> event loop like QSA did?
<http://doc.trolltech.com/4.3/qscriptengine.html#setProcessEventsInterval>
does the trick.
Frank
--
[ signature omitted ]
Dmitry Nezhevenko wrote:
> Hi. I'm trying to add script support to existing Qt app. Basically I want
> to give end-user way to execute own script files. It works as expected,
> however I have one problem. User can create some script like:
>
> while (1)
> {
> }
>
> And app will freeze forever. Yes, I can execute scripts in non-GUI thread
> and there will be no app freeze. But I will get "script" thread freeze...
>
> Any way to set some kind of time-limit to script execution? Or maybe there
> is some correct way to terminate execution from another thread?
>
> I can call QThread::terminate() for script thread, but as for me, this
> isn't correct solution.
Hi Dmitry,
You should use:
http://doc.trolltech.com/4.3/qscriptengine.html#setProcessEventsInterval
Which makes sure the eventloop is running periodically, even though the
script is blocking. From an event handler you can then again call
throwError() on the engine to stop the execution.
best regards,
Gunnar
--
[ signature omitted ]