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_DontCreateNativeWidgetSiblings

    Basically, this warning seems to come about because I'm using a QQuickWidget as a container widget for a QWidget. As soon as I hide the child QWidget then the warning disappears.

    I have tried setting the AA_DontCreateNativeWidgetSiblings attribute 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 > other QWidgets

    The child QWidget of the QQuickWidget fills the parent area entirely so that the contents of the QQuickWidget cannot be seen (but still must be "visible" so that the QML is rendered). At regular intervals, the QQuickWidget is grabbed and the resulting QPixmap is then drawn onto the child QWidget (along with some other stuff, which uses the winId of the QWidget to 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 the QWidget child of the QQuickWidget?



  • @webzoid
    I have no idea, since I have never used QQuick anything :) 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 QQuickWidget is a "native child" of the parent QWidget AND 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 QQuickWidget being a native child, then its strange that the warning disappear when I hide the child QWidget - the QQuickWidget isn't hidden and its parent hasn't changed.


  • Qt Champions 2016

    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 QWidgets application:

    Steps to re-create:

    1. Create a new QWidgets application
    2. Add qml quick quickwidgets to the .pro file
    3. Add a new class called MyQuickWidget and derive it from QQuickWidget
    4. Add a new class called MyWidget and derive it from QWidget
    5. In the MainWindow designer, add a Widget to the centralWidget and change the layout of the centralWidget to grid. Remove all margins and promote this widget to MyQuickWidget
    6. Drop a Widget on top of the new widget from above. Change the layout of the MyQuickWidget to grid and again, remove all padding. Promote this new Widget to MyWidget
    7. Add a QML file to the project called MyQml.qml
    8. Add a resource file to the project called MyResources and add MyQml.qml to the resources
    9. Time to add some code:

    In the MyQuickWidget add the following into the constructor after setupUI:

    setSource(QUrl("qrc:/MyQml.qml");
    

    In the MyWidget header file, add an override to the paintEvent and include any necessary header files. Implement this paintEvent function 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.qml file:

    import QtQuick 2.0
    
    Rectangle {
        id: rect
        color: "blue"
        width: 240
        height: 240
    }
    

    Now if you run qmake and 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.cpp also makes no difference:

    QApplication a(argc, argv);
    a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
    

    But obviously, commenting out the following line from MyWidget.cpp solves the problem:

    //WId hWnd = this->winId();
    

    However, my application NEEDS the hwnd of 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 MyQuickWidget on the form, you will see that the QML rendering is "broken" and a black window is show behind the MyWidget widget. I can still successfully grab the MyQuickWidget as it still renders correctly to its framebuffer.


  • Qt Champions 2016

    @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_DontCreateNativeAncestors doesn'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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.