Results 1 to 6 of 6

Thread: emit signal from script

  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default emit signal from script

    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:

    Qt Code:
    1. To emit a signal from script code, you simply invoke the signal function, passing the relevant arguments:
    2. myQObject.somethingChanged("hello");
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: emit signal from script

    Invoke the signal function instead

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: emit signal from script

    Signal/slot always requires objects.

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

    Qt Code:
    1. QScriptEngine* eng ..;
    2. ..
    3. MyObject* myobject = new MyObject();
    4. QObject::connect(myobject,SIGNAL(finished()),this,SLOT(calculationFinished()));
    5. eng->globalObject().setProperty("myobject", eng->newQObject(myobject));
    6. eng->evaluate( .. calculation script .. );
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: emit signal from script

    Quote Originally Posted by JohannesMunk View Post
    Signal/slot always requires objects.

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

    Qt Code:
    1. QScriptEngine* eng ..;
    2. ..
    3. MyObject* myobject = new MyObject();
    4. QObject::connect(myobject,SIGNAL(finished()),this,SLOT(calculationFinished()));
    5. eng->globalObject().setProperty("myobject", eng->newQObject(myobject));
    6. eng->evaluate( .. calculation script .. );
    To copy to clipboard, switch view to plain text mode 

    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?

  5. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: emit signal from script

    Just write "myobject.finish();" in your script code, as fatjuicymole wrote..

    Joh

  6. #6
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: emit signal from script

    I just try,it is done. thank you very much!

Similar Threads

  1. emit signal from a slot?
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 9
    Last Post: 11th June 2010, 20:18
  2. Emit signal from thread
    By sisco in forum Newbie
    Replies: 2
    Last Post: 26th November 2009, 13:32
  3. signal doesnt emit
    By mark2804 in forum Newbie
    Replies: 2
    Last Post: 25th December 2008, 22:36
  4. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 14:26
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.