Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

inizialize



  • I have this error in my app.

    QtWebEngine::initialize() must be called after the construction of the application object.
    

    But I have put intialize after .. Whay this ?

    9a9953a4-2b67-4324-a947-b9bef6774a45-image.png



  • @elicat
    https://doc.qt.io/qt-5/qtwebengine.html#initialize states:

    Sets up an OpenGL Context that can be shared between threads. This has to be done before QGuiApplication is created and before window's QPlatformOpenGLContext is created.

    So I don't know about the error message, but the docs state before, and that's where I do mine. Try swapping the order!?



  • @JonB said in inizialize:

    So I don't know about the error message, but the docs state before, and that's where I do mine. Try swapping the order!?

    I have try several times. the result it's same

    88d44884-b637-4fd3-9ee5-d5c8a8b301d7-image.png

    6b58c39b-99b6-4236-a2b2-2a2fed8062d2-image.png



  • @elicat
    Hmm. I don't even use that function. Are you using Qt Quck, or just standard widgets? Because that doc above sates:

    Helper functions for the Qt WebEngine (Qt Quick) module

    ? Because all I do (I'm afraid I'm Python/PyQt5) is:

        # next line required to avoid
        #   "QtWebEngineWidgets must be imported before a QCoreApplication instance is created", or related problem
        try:
            from PyQt5.QtWebEngineWidgets import QWebEngineView
        except:
            pass
    
        # create the QGuiApplication
        app = QtWidgets.QApplication(sys.argv)
    


  • @JonB said in inizialize:

    Hmm. I don't even use that function. Are you using Qt Quck, or just standard widgets? Because that doc above sates:

    I don't use widgets. For My project i use QML and inside I set webengine e dynamic url.
    I use QT Tools Into VisualStudio Comunity 2017

    218d9e46-1430-4b26-bf77-a4fe8d7bf32f-image.png



  • @elicat
    Apologies, I had no idea you were using QML. You'll have to await another responder.



  • Thanks, however the problem is not the QML but the initialization command.
    I hope resolve it quickly



  • @elicat
    The initialization command is only used from Qt Quick/QML. From Qt widgets I have no initialization command and it works fine....



  • @elicat
    OK, did you try Googling for QML QWebEngine...? Because there is an example I see at https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html:

    Initializing Web Engine

    For the web engine view to be rendered, the web engine must be initialized by using QtWebEngine::initialize in the application main source file, as illustrated by the following code snippet:

    int main(int argc, char *argv[])
    {
        QCoreApplication::setOrganizationName("QtExamples");
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QtWebEngine::initialize();
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    

    As I originally suggested, it seems to call the initialize() before the QGuiApplication(). Try the above code, at least to see whether you get the error you report?



  • @JonB said in inizialize:

    As I originally suggested, it seems to call the initialize() before the QGuiApplication(). Try the above code, at least to see whether you get the error you report?

    My code it's same this.

    I have two strange things.

    1. The QtWebEngine class is recognized but not highlighted as a class
    2. if I delete the initialization line the application starts and works

    Obviously it's not a correct thing and it's clear so I'm trying to understand

    82e203d0-f00a-4675-9b3c-b3b843fb5e8e-image.png



  • @elicat Nobody have idea?
    If I insert the initialization line, before or after "QGuiApplication app", the error is reported to me (see previous post), why?
    If I delete the webengine initialization line the program works (in QT 511.1), why is this possible?



  • I have solved when installed version QT 5.14.0


Log in to reply