PDA

View Full Version : emit signal from script



wookoon
6th July 2010, 07:45
If executing a script needs a long time,so I want emit a signal to the application after it finish. I am I need

some suggestions to realize it.

the ways provided by qt doc is likes this:



To emit a signal from script code, you simply invoke the signal function, passing the relevant arguments:
myQObject.somethingChanged("hello");


it need some object,but I just want emit a signal.

squidge
6th July 2010, 08:19
Invoke the signal function instead

JohannesMunk
6th July 2010, 11:41
Signal/slot always requires objects.

You will need to add a QObject to your scripting environment, with


QScriptEngine* eng ..;
..
MyObject* myobject = new MyObject();
QObject::connect(myobject,SIGNAL(finished()),this, SLOT(calculationFinished()));
eng->globalObject().setProperty("myobject", eng->newQObject(myobject));
eng->evaluate( .. calculation script .. );


That myobject could also hold the required parameters for your calculation..

I assume, you have put the scriptengine into another thread. Because if you call eng->evaluate directly, it won't return until the calculation is finished and you can emit your signal directly afterwards..

Joh

wookoon
6th July 2010, 14:13
Signal/slot always requires objects.

You will need to add a QObject to your scripting environment, with


QScriptEngine* eng ..;
..
MyObject* myobject = new MyObject();
QObject::connect(myobject,SIGNAL(finished()),this, SLOT(calculationFinished()));
eng->globalObject().setProperty("myobject", eng->newQObject(myobject));
eng->evaluate( .. calculation script .. );


That myobject could also hold the required parameters for your calculation..

I assume, you have put the scriptengine into another thread. Because if you call eng->evaluate directly, it won't return until the calculation is finished and you can emit your signal directly afterwards..

Joh

how emit the finish() signal? can you talk about it?

JohannesMunk
6th July 2010, 14:19
Just write "myobject.finish();" in your script code, as fatjuicymole wrote..

Joh

wookoon
6th July 2010, 14:37
I just try,it is done. thank you very much!