如何断开QtScript中所有连接的连接

时间:2013-06-18 05:13:40

标签: c++ qt qtscript qt-signals

我在我的应用程序中使用QtScript。脚本由用户编写。 像这样的示例脚本:

//<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();

我希望C ++在测试时间过去之前停止这个脚本并像这样编写函数

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
}

如何正确断开连接?

1 个答案:

答案 0 :(得分:0)

您可以断开各个信号和插槽:

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

来源:http://www.developer.nokia.com/Community/Wiki/Understanding_Signals_and_Slot_in_Qt

要获取接收器,请使用QObject :: receivers():

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

似乎你无法获得插槽(你必须自己跟踪连接):

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

然而,有......

...调试信号和插槽的方法:

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