4

I have this small piece of code:

#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();
}

I display a QWidget which displays a QMessageBox after two seconds. If I am resizing my main window when the popup is displayed, my mouse cursor does not come back to normal (it keeps a "resizing a Window" look) and the interface is completely frozen. I cannot close the popup and I cannot move my mouse over the Taskbar.

The only solution is to navigate with ALT+TAB to Visual studio and stop the debugger.

System (if it matters):

  • Windows 7 64 bit.
  • Visual Studio 2013 + Addin
  • Qt 5.3.0 alpha

My questions:

  • Is it a known bug?
  • Am I doing something wrong?
  • Is there a simple workaround?
NG_
  • 6,895
  • 7
  • 45
  • 67
Arnaud
  • 3,765
  • 3
  • 39
  • 69
  • I think your question might be related to [this one](http://stackoverflow.com/questions/6383464/qmessagebox-blocks-qdialog) – maddin45 Apr 10 '14 at 13:50
  • @maddin45 I do not think it is. I know that I have a modal Dialog Box. My problem is that I cannot even click on the message box itself. – Arnaud Apr 10 '14 at 13:53
  • Snippet is not working at all... – Thomas Ayoub Apr 10 '14 at 13:54
  • @Samoth Sorry. I posted a corrected version. I tested it in Qt Creator and Visual Studio. – Arnaud Apr 10 '14 at 14:01
  • It seems to be a bug introduced in Qt5. I tested and can confirm the same behaviour in 5.2.0 but not in 4.8.4 – Uflex Apr 10 '14 at 14:03
  • I can't reproduce the freeze, using mac OS and Qt5.2.1, sorry. – Thomas Ayoub Apr 10 '14 at 14:08
  • May be it doesn't work, when tries to process window event while processing another window event? \Try to use QTimer with the signal instead of QBasicTimer and event. – Lol4t0 Apr 10 '14 at 14:28
  • @Lol4t0 it doesn't change anything to use a QTimer, I just tried and got the same behaviour. – Uflex Apr 10 '14 at 14:31
  • It could be an old bug that came back from the dead with Qt5: https://bugreports.qt-project.org/browse/QTBUG-15451 Weirdly it doesn't block on Qt 4.8.4 though... – Uflex Apr 10 '14 at 14:44
  • For everything which is bug related in qt, you should post to their qt-interest mailing list – galinette Apr 11 '14 at 07:07
  • I tested QT 4.7 in windows, behavior is not correct either. The window will snap back to its original size. – m. c. Apr 11 '14 at 16:43

1 Answers1

1

According to Digia Support, this is a bug. However, they provide an acceptable workaround.

Just before the QMessageBox::critical we can add a ReleaseCapture(); like this:

#ifdef Q_OS_WIN
    ReleaseCapture();
#endif

The behavior goes back to Qt 4.7 though (cf comment from user3183610). The window will snap back to its original size.

Arnaud
  • 3,765
  • 3
  • 39
  • 69
  • Can you please attach a link of the bug? – willy Feb 25 '22 at 11:14
  • 1
    @michalis Qt has changed its bug reporting tool. If the [link](https://bugreports.qt.io/browse/QTBUG-15451) I provided years ago does not work anymore, I am afraid you are out of luck. – Arnaud Feb 25 '22 at 13:34