10

When I run my Qt application I get the message

Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute before constructing QGuiApplication.

The app runs fine regardless of the fact that this is getting dumped to the terminal. I cant seem to find the root cause or really understand what this message is trying to tell me. What is this message saying and how can I fix it?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Mitch
  • 3,342
  • 2
  • 21
  • 31
  • It looks like it's an old bug. Are you using the latest version of PyQt5 and PyQtWebengine? check this thread: https://bugreports.qt.io/browse/QTBUG-51379 – eyllanesc May 16 '19 at 01:11
  • 1
    Still an issue in Qt 6.2.3 (without Python). Accepted solution doesn't explain why this is necessary or what it does. – Heath Raftery Mar 21 '22 at 14:27

2 Answers2

25

This can be fixed by setting AA_ShareOpenGLContexts before Spawning the QApplication.

See below an example when using PySide2

  from PySide2 import QtCore, QtWidgets

  if __name__ == '__main__':
      QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
      qt_app = QtWidgets.QApplication(sys.argv)

NB: As mentioned as reply in the question: When using PyQt5, checkout https://bugreports.qt.io/browse/QTBUG-51379 instead ...

harmv
  • 1,905
  • 22
  • 22
  • 2
    Even after adding this line, the issue persists. – NL23codes Feb 20 '20 at 19:04
  • The message comes up right after QWebEngineView is imported and before the app is even created. So this line would come after the problem has already occurred. – NL23codes Feb 21 '20 at 01:30
  • thanks -> normally Qt automatically creates in '__main__' -> app = QApplication([]) -> so when I change as you suggested, the bug disappeared. the main reason we chose PySide2 – ati ince May 14 '21 at 10:50
  • 1
    Problem occurred for me using pyside6, just had to adjust the import line to`from PySide6.QtCore import QFile, QCoreApplication, Qt` and omit the `QtCore` namespace from the function calls – richbai90 Dec 03 '21 at 20:00
0

Using PySide6 instead of PySide2 solved my problem with python 3.9 and QT 5.15 if it can help