When a multi-head setup is used, QWidget::winId() is broken. (I have a test case attached which can reproduce the bug).
QWidget/QWindow may re-create the underlying window and change WinId() at runtime. However, QEvent::WinIdChange is not always emitted and QWidget::winId() always return the old value. Then, I got error message from QBackStore stating that the window has no handle and the window disappeared.
Steps to reproduce the bug:
1. Run the test program and use "xwininfo" command to check its window ID.
2. Plug in an external monitor
3. Use xrandr to get a dual monitor setup with the external monitor attached to the right border of the primary monitor.
4. Move the window of the test program to the external monitor.
5. Use xrandr to turn off the external monitor.
6. My test program will move the window back to the primary monitor when the external monitor is turned off (it listens to QDesktopWindow::screenCountChanged() signal)
7. Use "xwininfo" command to inspect the window of the test program
8. You'll notice that the window ID is changed as shown by xwininfo. However, effectiveWindowId() still returns the old value.
If you repeat the steps for many times, the test program will crash with a broken QBackingStore and an invalid window handle.
This only happens in Qt5. I also tested Qt 4.8 and it does not have the bug.
Please fix the regression bug. Forgetting to update the internal winId can crash the program so this is very critical.