如何防止显示 QMessageBox 时出现双槽调用
How to prevent double slot invocation when showing a QMessageBox?
>我已经将QLineEdit的editFinish信号连接到应用程序中的一个插槽,如果输入以某种方式出乎意料,则显示QMessageBox。奇怪的是,消息框显示两次,所以我在执行它的位置放置了一个断点并查看了堆栈跟踪。在那里,QMessageBox.exec()调用QApplication::p rocessEvents(),它似乎以某种方式再次转发和处理相同的事件。
我第一次的堆栈跟踪看起来像这样:
MyApp::mySlot()
QLineEdit::editingFinished()
QGuiApplicationPrivate::processMouseEvent()
QEventLoop::processEvents()
QApplication::exec()
第二次像这样:
MyApp::mySlot()
QLineEdit::editingFinished()
QGuiApplicationPrivate::processWindowSystemEvent()
QEventLoop::processEvents()
QDialog::exec()
// stack trace of run #1 here
// [...]
我已经检查了双信号连接或连接到此插槽的不同事件,但这似乎不是问题。有人可以解释一下这里发生了什么以及如何预防它吗?
这是一个 Qt 错误,编辑完成被发出两次,你可以在这里阅读它:
https://forum.qt.io/topic/39141/qlineedit-editingfinished-signal-is-emitted-twice
还有一个解决方法。
if(lineEdit->text().toDouble()<1000) {
lineEdit->blockSignals(true);
QMessageBox::information(this, "Information", "Incorrect value");
lineEdit->blockSignals(false);
}
相关文章:
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何防止clang格式在流运算符调用之间添加换行符<<
- C++ 防止在映射中放置()时调用析构函数
- 每个线程 C++ 保护以防止重入函数调用
- 防止我的向量在调用它的函数结束时被删除
- 防止 CRTP 特征码在"pure virtual"调用中堆栈溢出
- 如何防止方法的调用方将结果存储在C++中
- 防止调用某些 std 函数
- 通过 system() 函数调用防止野卡扩展
- 防止线程在处理异常后在分离时调用 std::terminate()
- 防止const函数被调用非const对象
- 如何防止递归功能调用(尾部回复)堆积在堆栈中
- 防止在C++中调用基本分配运算符
- 如何安全地防止在 Wininet 中调用状态回调函数
- 如何防止使用临时调用构造函数
- 如何防止在基类初始化器中调用默认构造函数?
- 防止删除对象上的函数调用
- C++17标准对在nullptr上调用delete有何规定
- 有没有一种方法可以防止基类方法在派生类的实例上被调用
- 超时 fwrite 调用以防止其阻塞