0

I use QtScript in my application. Scripts are written by users. As example script like this:

//<init test time counters>

function testIteration() {
    if (<test time is out>) {
    myCppObject.mySignalAllDone.disconnect(testIteration);//disconnection
        return;    
    }
    //<Adding actions to myCppObject>
}
myCppObject.mySignalAllDone.connect(testIteration);//connection
testIteration();

I want from C++ stop this script before test time passed and write function like this

void MainWindow::toolButtonStopScript_clicked(){    
    disconnect(&this->myCppObject);// Disconnecting everything connected to myCppObject.
    this->scriptEngineThread.abortAllEvaluations();
    myCppObject.stopAllActivity();// emits mySignalAllDone, that is not disconnected (why and how to do that if I don't know what connections user made?), calling testIteration(), appending activity to myCppObject and this ends only when test time passed. How to solve this?
    this->guiLog.log(GUILog::log_info, tr("Execution of script is interrupted by user"), this->logLevelMsgs);
    this->connectMyCppObject();//make default connections
}

How to disconnect properly?

Sacha_D
  • 68
  • 1
  • 10

1 Answers1

0

You can disconnect individual signals and slots:

disconnect(sender0, SIGNAL(overflow()),receiver1, SLOT(handleMathError()));

source: http://www.developer.nokia.com/Community/Wiki/Understanding_Signals_and_Slot_in_Qt

To get receivers, use QObject::receivers():

http://qt-project.org/doc/qt-4.8/qobject.html#receivers

It seems you cannot get slots (you must keep track of connections by yourself):

http://qt-project.org/forums/viewthread/6820

However, there are...

...Ways to debug signals and slots:

http://samdutton.wordpress.com/2008/10/03/debugging-signals-and-slots-in-qt/

user2448027
  • 1,628
  • 10
  • 11