Suppress Specific Qt Warning
-
I'm trying to understand whether I can suppress the following warning:
QQuickWidget cannot be used as a native child widget. Consider setting Qt::AA_DontCreateNativeWidgetSiblingsBasically, this warning seems to come about because I'm using a
QQuickWidgetas a container widget for aQWidget. As soon as Ihidethe childQWidgetthen the warning disappears.I have tried setting the
AA_DontCreateNativeWidgetSiblingsattribute for the application but this makes not a jot of difference and the warning still remains. Each time a mouse/paint/other event occurs, this warning is displayed and makes it difficult to see any other warnings, etc.Any help would be greatly appreciated.
-
I'm trying to understand whether I can suppress the following warning:
QQuickWidget cannot be used as a native child widget. Consider setting Qt::AA_DontCreateNativeWidgetSiblingsBasically, this warning seems to come about because I'm using a
QQuickWidgetas a container widget for aQWidget. As soon as Ihidethe childQWidgetthen the warning disappears.I have tried setting the
AA_DontCreateNativeWidgetSiblingsattribute for the application but this makes not a jot of difference and the warning still remains. Each time a mouse/paint/other event occurs, this warning is displayed and makes it difficult to see any other warnings, etc.Any help would be greatly appreciated.
@webzoid said in Suppress Specific Qt Warning:
AA_DontCreateNativeWidgetSiblings
This post http://lists.qt-project.org/pipermail/interest/2015-June/017391.html seems to say you need an extra flag. Having said that, the reply http://lists.qt-project.org/pipermail/interest/2015-June/017392.html implies it still didn't work for him, but it might be worth a try....
Also, https://git.merproject.org/mer-core/qtdeclarative/commit/c9553ad7d8041c7b0fd769dc8cd0f5335d9408a3 says explicitly:
Detect and warn when using QQuickWidget as a native child
This is not supported.though this seems to be the opposite way round from your:
Basically, this warning seems to come about because I'm using a QQuickWidget as a container widget for a QWidget.
-
@JNBarchan thanks for your comments.
Just to clarify, I have the following heirarchy on my
QMainWindow:QWidget>QQuickWidget>QWidget> otherQWidgetsThe child
QWidgetof theQQuickWidgetfills the parent area entirely so that the contents of theQQuickWidgetcannot be seen (but still must be "visible" so that the QML is rendered). At regular intervals, theQQuickWidgetis grabbed and the resultingQPixmapis then drawn onto the childQWidget(along with some other stuff, which uses thewinIdof theQWidgetto enable a 3rd party COM object to draw).Complex, I know but it works.
Looking at the
Qt::WA_DontCreateNativeAncestors, would this attribute need to be set in theQWidgetchild of theQQuickWidget? -
@JNBarchan thanks for your comments.
Just to clarify, I have the following heirarchy on my
QMainWindow:QWidget>QQuickWidget>QWidget> otherQWidgetsThe child
QWidgetof theQQuickWidgetfills the parent area entirely so that the contents of theQQuickWidgetcannot be seen (but still must be "visible" so that the QML is rendered). At regular intervals, theQQuickWidgetis grabbed and the resultingQPixmapis then drawn onto the childQWidget(along with some other stuff, which uses thewinIdof theQWidgetto enable a 3rd party COM object to draw).Complex, I know but it works.
Looking at the
Qt::WA_DontCreateNativeAncestors, would this attribute need to be set in theQWidgetchild of theQQuickWidget?@webzoid
I have no idea, since I have never usedQQuickanything :) You can doubtless experiment.However, you now say you have:
QWidget > QQuickWidget > QWidget > other QWidgets
So that means you are using "QQuickWidget as a native child", aren't you? Which the git project explicitly states is "not supported" and put in the error message you see for. So I don't know whether your code works or not, but it seems the warning message is there deliberately for this case....
-
@JNBarchan Yes, the
QQuickWidgetis a "native child" of the parentQWidgetAND the project works perfectly, no issues at all other than this warning.What is odd though, is that if this warning is to do with the
QQuickWidgetbeing a native child, then its strange that the warning disappear when I hide the childQWidget- theQQuickWidgetisn't hidden and its parent hasn't changed. -
@JNBarchan Yes, the
QQuickWidgetis a "native child" of the parentQWidgetAND the project works perfectly, no issues at all other than this warning.What is odd though, is that if this warning is to do with the
QQuickWidgetbeing a native child, then its strange that the warning disappear when I hide the childQWidget- theQQuickWidgetisn't hidden and its parent hasn't changed.Please provide the code which you use to create that hierarchy of widgets and the relevant window attributes you set to them. Also any retrievals of the native window handle are relevant, so post these as well.
-
@kshegunov There's a LOT of source code and its not going to be easy picking it apart to get the relevant bits. I have, however, re-created the problem in a separate
QWidgetsapplication:Steps to re-create:
- Create a new QWidgets application
- Add
qml quick quickwidgetsto the .pro file - Add a new class called
MyQuickWidgetand derive it fromQQuickWidget - Add a new class called
MyWidgetand derive it fromQWidget - In the
MainWindowdesigner, add aWidgetto thecentralWidgetand change the layout of thecentralWidgetto grid. Remove all margins and promote this widget toMyQuickWidget - Drop a
Widgeton top of the new widget from above. Change the layout of theMyQuickWidgetto grid and again, remove all padding. Promote this newWidgettoMyWidget - Add a QML file to the project called
MyQml.qml - Add a resource file to the project called
MyResourcesand addMyQml.qmlto the resources - Time to add some code:
In the
MyQuickWidgetadd the following into the constructor aftersetupUI:setSource(QUrl("qrc:/MyQml.qml");In the
MyWidgetheader file, add an override to thepaintEventand include any necessary header files. Implement thispaintEventfunction in the cpp file as follows:void MyWidget::paintEvent(QPaintEvent *event) { QPainter p(this); // Get the HWND (this is needed for the COM object of my application) WId hWnd = this->winId(); p.fillRect(event->rect(), QColor("red")); }Finally, add the following to the
MyQml.qmlfile:import QtQuick 2.0 Rectangle { id: rect color: "blue" width: 240 height: 240 }Now if you run
qmakeand then debug the application, the warning from the original post starts to appear. Resizing the window or forcing a repaint generates hundreds of warnings.Adding the following attribute into
main.cppalso makes no difference:QApplication a(argc, argv); a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);But obviously, commenting out the following line from
MyWidget.cppsolves the problem://WId hWnd = this->winId();However, my application NEEDS the
hwndof the widget in order to paint the 3rd party control as well as the QML in the background in order to pull in and paint the QML-only stuff.EDIT: If you change the margins of the
MyQuickWidgeton the form, you will see that the QML rendering is "broken" and a black window is show behind theMyWidgetwidget. I can still successfullygrabtheMyQuickWidgetas it still renders correctly to its framebuffer. -
@kshegunov There's a LOT of source code and its not going to be easy picking it apart to get the relevant bits. I have, however, re-created the problem in a separate
QWidgetsapplication:Steps to re-create:
- Create a new QWidgets application
- Add
qml quick quickwidgetsto the .pro file - Add a new class called
MyQuickWidgetand derive it fromQQuickWidget - Add a new class called
MyWidgetand derive it fromQWidget - In the
MainWindowdesigner, add aWidgetto thecentralWidgetand change the layout of thecentralWidgetto grid. Remove all margins and promote this widget toMyQuickWidget - Drop a
Widgeton top of the new widget from above. Change the layout of theMyQuickWidgetto grid and again, remove all padding. Promote this newWidgettoMyWidget - Add a QML file to the project called
MyQml.qml - Add a resource file to the project called
MyResourcesand addMyQml.qmlto the resources - Time to add some code:
In the
MyQuickWidgetadd the following into the constructor aftersetupUI:setSource(QUrl("qrc:/MyQml.qml");In the
MyWidgetheader file, add an override to thepaintEventand include any necessary header files. Implement thispaintEventfunction in the cpp file as follows:void MyWidget::paintEvent(QPaintEvent *event) { QPainter p(this); // Get the HWND (this is needed for the COM object of my application) WId hWnd = this->winId(); p.fillRect(event->rect(), QColor("red")); }Finally, add the following to the
MyQml.qmlfile:import QtQuick 2.0 Rectangle { id: rect color: "blue" width: 240 height: 240 }Now if you run
qmakeand then debug the application, the warning from the original post starts to appear. Resizing the window or forcing a repaint generates hundreds of warnings.Adding the following attribute into
main.cppalso makes no difference:QApplication a(argc, argv); a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);But obviously, commenting out the following line from
MyWidget.cppsolves the problem://WId hWnd = this->winId();However, my application NEEDS the
hwndof the widget in order to paint the 3rd party control as well as the QML in the background in order to pull in and paint the QML-only stuff.EDIT: If you change the margins of the
MyQuickWidgeton the form, you will see that the QML rendering is "broken" and a black window is show behind theMyWidgetwidget. I can still successfullygrabtheMyQuickWidgetas it still renders correctly to its framebuffer.@webzoid said in Suppress Specific Qt Warning:
// Get the HWND (this is needed for the COM object of my application) WId hWnd = this->winId();This will create a native handle for that widget (if not done already) and will thus generate your warning.
Qt::WA_DontCreateNativeAncestorsdoesn't have any effect in this case, as you explicitly require the widget to be a native one. Consider using QQuickRenderControl for your task instead.A note of caution about this:
You can ignore the warning and it may work fine now, but there's no guarantee that a future version of Qt won't break this code. Warnings reported from Qt should be considered bugs in the user code and ought to be fixed.