Qt5 "Attempt to set a screen on a child window"许多运行时警告消息



在我们基于Qt5的应用程序中,控制台中显示了许多这样的消息:

0x1beccb0 void QWindowPrivate::setTopLevelScreen(QScreen*, bool) ( QScreen(0xd25b80) ): Attempt to set a screen on a child window.

它不会阻止应用程序运行,但我想修复它们,因为它往往表明我们正在做的事情可能有问题。代码相当大(不能包含在帖子中,它在那里:http://gforge.inria.fr/frs/?group_id=1465)。我不能要求你看一看它(太大了),但也许你会对以下额外信息有一个想法:

  1. 这些消息仅在Linux下显示,而不在Windows 下显示

  2. 我们的应用程序是一个3D建模器,它有几个QGLWidget用于显示3D内容。如果我删除QGLWidgets,则消息消失

  3. 在调试器中,如果我在QWindowPrivate::setTopLevelScreen(),由:调用

    kernel/qwindow.cpp:368368 q->connect(screen,SIGNAL(destroyed(QObject*)),q,SLOT(screenDestroyed(QObject*);

更新1:我在QMessageLogger::warning上放置了一个断点(qDebug()是一个使用此函数的宏),现在我可以更好地看到堆栈,它看起来像:

#0  0x00007fffefa50600 in QMessageLogger::warning() const@plt () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#1  0x00007fffefa851cb in QWindowPrivate::setTopLevelScreen (this=0xd330e0, newScreen=0x7201a0, recreate=<optimized out>)
    at kernel/qwindow.cpp:371
#2  0x00007fffefa7f2f5 in QGuiApplicationPrivate::processWindowSystemEvent (e=e@entry=0x760600)
    at kernel/qguiapplication.cpp:1608
#3  0x00007fffefa631f8 in QWindowSystemInterface::sendWindowSystemEvents (flags=...)
    at kernel/qwindowsysteminterface.cpp:625
#4  0x00007fffeb7d4100 in userEventSourceDispatch (source=<optimized out>)
    at eventdispatchers/qeventdispatcher_glib.cpp:70
(More stack frames follow...)

在QGuiApplicationPrivate::processWindowSystemEvent中,它正在处理一个QWindowSystemInterfacePrivate::ThemeChange事件:

1608        case QWindowSystemInterfacePrivate::ThemeChange:
1609            QGuiApplicationPrivate::processThemeChanged(
1610                        static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
1611            break;

更新2:快到了!!这是当我在QGLWidget上调用setMinimumWidth()/setMinimumHeight()时。现在我想知道为什么。。。

更新3:更多信息:只有当我的电脑连接了两个屏幕时,才会显示这些信息。

最后,我明白了发生了什么:

  • 每当在具有双屏显示的Linux下的QGLWidget上调用setMinimumWidth()/setMinimumHeight()时,就会出现警告消息

这可能是Qt中的一个错误。它可能不会被修复,因为文档中建议使用Qt 5.4中出现的新QOpenGLWidget(注意:"OpenGL"而不是"GL"),我这样做了,警告消息消失了。

编辑:我看到有人发来消息,说新的QOpenGLWidget无法正确渲染文本,我在这里回答:当使用新的QOpenGLWidget时,需要注意它不再有独立的OpenGL上下文,它与Qt共享OpenGL上下文(因此,在渲染功能中修改的OpenGL状态需要在退出渲染功能后恢复,例如混合模式)。

最新更新