0

我在我的应用程序中使用 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
}

如何正确断开连接?

4

1 回答 1

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/

于 2013-06-18T06:12:04.393 回答