在基于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)。我不能要求您研究它(太大),但是也许您会想到以下补充信息:
显示3D内容。如果我删除了QGLWidgets,则消息
消失。
QWindowPrivate::setTopLevelScreen(),由以下方式调用:
内核/qwindow.cpp:368
第368章(小幸运)
Update1:
我在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;
Update2:
就快到了 !!当我在QGLWidget上调用setMinimumWidth()/setMinimumHeight()时。现在我想知道为什么...
Update3:
详细信息:仅当我有两个连接到计算机的屏幕时,才会显示消息。
最佳答案
最终,我了解了会发生什么:
这可能是Qt中的错误。它可能不会固定,因为在文档中建议使用新的QOpenGLWidget代替,它出现在Qt 5.4中(请注意:“OpenGL”而不是“GL”),我这样做了,警告消息也消失了。
编辑:我看到某人发来的消息,该人在使用新的QOpenGLWidget无法正确呈现文本时遇到问题,我在这里回答:使用新的QOpenGLWidget时,需要注意它不再具有独立的OpenGL上下文,它会共享具有Qt的OpenGL上下文(因此,退出渲染功能(例如混合模式)后,需要还原在渲染功能中修改的OpenGL状态)。
关于Qt5 "Attempt to set a screen on a child window"许多运行时警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33545006/