Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-125293

Allow to set theMainThread from QCoreApplication if initialized from own thread

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 6.4.2
    • Core: Threads, WebEngine
    • None
    • Linux/Other display system, Windows

    Description

      If the QT application and WebEngine is initialized from an own thread, then it is required to set the QCoreApplicationPrivate::theMainThread first to get ride of all warnings.
      Note that in our application it is required to use a dedicated thread and the initialization cannot be performed on the main thread.

      I have tried 3 different variants. See also attached project.

      Variant 1 as shown by https://doc.qt.io/qt-6/qtwebengine-overview.html

      QGuiApplication app(argc, argv);
      QtWebEngineQuick::initialize();
      ==> shows Warnings
       WARNING: QApplication was not created in the main() thread.
       QtWebEngineQuick::initialize() called with QCoreApplication object already created and should be call before. This is depreciated and may fail in the future.
      

      Variant 2

      QtWebEngineQuick::initialize();
      QGuiApplication app(argc, argv);
      ==> shows Warning
        WARNING: QApplication was not created in the main() thread. 
      

      Variant 3 - Works without warnings but is not nice as it requires private includes of QCoreApplication 

      #include <QtCore/private/qcoreapplication_p.h>
      
      auto thread = QThread::currentThread();
      QCoreApplicationPrivate::theMainThread = thread;
      QtWebEngineQuick::initialize();
      QGuiApplication app(argc, argv);
      

      Suggestion: Make it possible to set QCoreApplicationPrivate::theMainThread somehow from the QCoreApplication.

      static QCoreApplication::useCurrentThreadAsMainThread()

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            bruno_g Bruno Gebert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes