gpt4 book ai didi

c++ - Qt - 当我在 qApp->processEvents() 期间关闭窗口时,程序仍在任务管理器中运行

转载 作者:行者123 更新时间:2023-11-30 05:40:21 25 4
gpt4 key购买 nike

我的应用程序绘制图像并为其添加标签。当窗口在等待输入时关闭,应用程序仍然在后台运行。这是我的捕获标签的函数示例。我是否遗漏了一些让程序正常退出的东西?

 void CustomMainWindow::CaptureLabel(void){

connect(measurementLabel,
SIGNAL(mousePressSignal()),
this,
SLOT(mouseLabel()),
Qt::DirectConnection
);

m_MouseCount = 0;
m_CurrentLabel = cv::Point2f(0.0, 0.0);

while(m_MouseCount < 1){
qApp->processEvents();

}

disconnect(measurementLabel,
SIGNAL(mousePressSignal()),
this,
SLOT(mouseLabel())
);
}

最佳答案

您可以轻松地使用状态机来指导您完成状态更改。这将消除您诉诸可怕的伪同步黑客的需要。

class CustomMainWindow : ... {
QStateMachine m_CaptureLabelMachine;
...
};

void CustomMainWindow::CaptureLabel(void){
if (!m_CaptureLabelMachine.findChild<QFinalState*>()) {
// build the state machine
auto machine = &m_CaptureLabelMachine;
auto s1 = new QState(machine), s2 = new QFinalState(machine);
machine->setInitialState(s1);
s1->addTransition(measurementLabel, SIGNAL(mousePressSignal()), s2);
connect(s1, &QState::entered, [this]{
connect(measurementLabel, SIGNAL(mousePressSignal()), SLOT(mouseLabel()));
m_MouseCount = 0;
m_CurrentLabel = cv::Point2f(0.0, 0.0);
});
connect(s2, &QState::entered, [this]{
disconnect(measurementLabel, SIGNAL(mousePressSignal()), SLOT(mouseLabel()));
});
}
m_CaptureLabelMachine.start();
}

关于c++ - Qt - 当我在 qApp->processEvents() 期间关闭窗口时,程序仍在任务管理器中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31665912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com