Using QGLWidget and QQuickWidget a the same time?
-
I have an app (music player) which uses QGLWidget for rendering a visualizer, and used to use QQuickView and QWidget::createWindowContainer() for creating some of the GUI. I saw that QQuickWidget is the replacement for that technique in 5.3, but upon switching to it I'm finding that the QQuickWidget renders only black as long as the QGLWidget has been instantiated. If I never create the QGLWidget, it works fine.
Is this expected? Can the two not be used together? Is there a workaround?
Any help is appreciated. I'm happy to provide code samples if that helps.
-
I experience something similar using QQuickWidget in an application containing the previous technique for embedding QML in QWidget applications: QQuickView and QWidget::createWindowContainer.
When I do NOT invoke QWidget::createWindowContainer to create a qml widget, everything works fine, the other "new style" QQuickWidget ist displayed.
When I invoke QWidget::createWindowContainer for creating the legacy widgets, the new QQuickWidget stays black.
Platform is Windows 7 x64.
-
There is a bug report for this issue: "QTBUG-39316":https://bugreports.qt-project.org/browse/QTBUG-39316
As Laszlo says in a comment, the workaround is to call:
@QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings)@ -
Hmm, unfortunately the workaround isn't doing it for me, the QQuickWidget is still black. I tried putting it as the first line in main() as suggested in the bug.
Thanks for the pointer to the bug though, at least it's actively being worked on.
-
For those googling:
A temporary workaround for me was to add this line to the widget inheriting from QGLWidget:
this->setAttribute(Qt::WA_DontCreateNativeAncestors); -
try adding QQuickWidget instance when the parent widget layout has been set, if necessary, use QMetaObject's invokeMethod with queued connection (or maybe invoke it with a QTimer::singleShot).
It will solve the problem, but here is the weird thing, i use OpenSceneGraph in my QGLWidget, and QQuickWidget stops updating itself. I have to resize or unfocus-focus to make QQuickWidget draw itself. I tried to set a timer to QQuickWidget's update slot, but had no chance.
P.S. used repaint instead of update, and it seems working right now. I will check the stability.