C++ 应用程序被QMessageBox冻结

C++ 应用程序被QMessageBox冻结,c++,qt,qt5,C++,Qt,Qt5,我有一小段代码: #include <QApplication> #include <QWidget> #include <QBasicTimer> #include <QMessageBox> class MyWidget:public QWidget{ public: QBasicTimer timer; protected: void timerEvent(QTimerEvent*e){ if(e->t

我有一小段代码:

#include <QApplication>
#include <QWidget>
#include <QBasicTimer>
#include <QMessageBox>

class MyWidget:public QWidget{
public:
    QBasicTimer timer;
protected:
    void timerEvent(QTimerEvent*e){
        if(e->timerId()==timer.timerId()){
            timer.stop();
            QMessageBox::critical(this,"Oups",
                                 "I hope you were not resizing the main window.");
            return;
        }
        QWidget::timerEvent(e);
    }
};

int main(int argc,char*argv[]){
    QApplication app(argc,argv);
    MyWidget w;
    w.timer.start(2000,&w);
    w.show();
    return app.exec();
}
#包括
#包括
#包括
#包括
类MyWidget:publicqwidget{
公众:
基本定时器;
受保护的:
无效timerEvent(QTimerEvent*e){
如果(e->timerId()==timer.timerId()){
timer.stop();
QMessageBox::critical(这是“Oups”,
“我希望您没有调整主窗口的大小。”);
返回;
}
QWidget::timerEvent(e);
}
};
int main(int argc,char*argv[]){
QApplication应用程序(argc、argv);
myw;
w、 定时器启动(2000和w);
w、 show();
返回app.exec();
}
我显示一个
QWidget
,它在两秒钟后显示一个
QMessageBox
。 如果弹出窗口显示时我正在调整主窗口的大小,则我的鼠标光标不会恢复正常(它保持“调整窗口大小”的外观),并且界面完全冻结。我无法关闭弹出窗口,也无法将鼠标移到任务栏上

唯一的解决方案是使用ALT+TAB导航到Visual studio并停止调试器

系统(如有必要):

  • Windows7 64位
  • Visual Studio 2013+插件
  • Qt 5.3.0阿尔法
我的问题:

  • 这是已知的错误吗
  • 我做错什么了吗
  • 有简单的解决方法吗

    • 根据Digia的支持,这是一个bug。但是,它们提供了一种可接受的解决方法

      就在
      QMessageBox::critical
      之前,我们可以添加一个
      ReleaseCapture()如下所示:

      #ifdef Q_OS_WIN
          ReleaseCapture();
      #endif
      

      但是,该行为可以追溯到Qt4.7(参见user3183610的注释)。窗口将恢复到原来的大小。

      我想你的问题可能与@maddin45有关,但我不这么认为。我知道我有一个模态对话框。我的问题是我甚至不能点击消息框本身。代码片段根本不起作用…@Samoth抱歉。我发布了一个更正的版本。我在QtCreator和VisualStudio中测试了它。它似乎是Qt5中引入的一个bug。我在5.2.0中进行了测试,可以确认相同的行为,但在4.8.4中没有