PDA

View Full Version : qscript suspend function?



reneb
26th February 2010, 23:31
Hello,

is it possible to suspend a function in qscript?

for example I have a c++ function called sleep(int ms);
which is called from within a script function.

and inside that c++ function I break the evaluation (save it somewhere)
and when the time elapsed resume the script.

Thanks in advance,
rene

JohannesMunk
27th February 2010, 10:23
What do you mean by "breaking the evaluation", saving it and resuming it later?

Sure you can call a sleep function from qscript. Do you need help in calling c++ functions from qscript?

What is your problem exactly? What do you want to achieve?

A sleep design pattern is probably not the best solution.. You can very easily connect script code to qt signals.

scriptcode: qtobj.signalname.connect(function SignalHandler(params) {});
or
scriptcode: qtobj.signalname.connect(scriptobj,scriptmethod);

HIH

Johannes

reneb
27th February 2010, 12:49
ok, the thing i'm working on is a card game.
In the script file I have multiple functions.
Which show some kind of animation. the animations are handled in de script like when dealing cards to the players; you see the cards moving from 1 position to the destination.
All objects are in a QGraphicsScene.
script is working, updates are done correctly but,

my problem is that for example; the cards dealing function; takes about 2 seconds
and when i call that script function from c++ it will wait till the function has ended.
I don't want to wait there for 2 seconds; because the animations are like frame updates
so inside the script loop for moving cards; i want to pause it for like 10ms

at that time the script is stopped; some kind of contextmanager holds it and checks when the script must resume again.
also the place in c++ from where the script is called will resume and no longer wait for the script to end


it's not difficult for me to just create a pause / sleep function which is called inside the script.
its more that while the script is running my c++ part stops executing
I cannot put the script call in a seperate thread because I get errors accessing QGraphicsItems

Hope my problem is more clear now.

Thanks,
Rene

JohannesMunk
27th February 2010, 13:03
Yes, your problem is now well described!

Mhh. Why don't you try to avoid that your animation blocks execution for its duration? You could use Timers and their slots, or the animation framework!

http://doc.trolltech.com/4.6/animation-overview.html (http://doc.trolltech.com/4.6/animation-overview.html)

For bindings to qtscript for both QTimer and the QAnimation-Classes have a look at the QtScriptBindingsGenerator

http://labs.trolltech.com/page/Projects/QtScript/Generator

http://qt.gitorious.org/qt-labs/qtscriptgenerator/commits/4.6

Works great for me!

Johannes