Hi community, I was faced with a warning QApplication was not created in the main() thread. on windows only, it is very rare happen, and I have dig a little bit a source code and found next situation: QCoreApplicationPrivate::theMainThread is declared as static variable in qcoreapplication.cpp QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(nullptr); It is initialized in QThreadData::current method, if use webenginecore, it is initialized in Q_CONSTRUCTOR_FUNCTION(initialize) in Qt6WebengineCore.dll, full stack:
> Qt6Cored.dll!QThreadData::current(bool createIfNecessary) Line 97 C++ > Qt6Cored.dll!QObject::QObject(QObjectPrivate & dd, QObject * parent) > Line 928 C++ > Qt6Cored.dll!QIODevice::QIODevice(QIODevicePrivate & dd, QObject * > parent) Line 491 C++ > Qt6Cored.dll!QFileDevice::QFileDevice(QFileDevicePrivate & dd, QObject * > parent) Line 217 C++ > Qt6Cored.dll!QFile::QFile(const QString & name) Line 266 C++ > Qt6Cored.dll!loadRulesFromFile(const QString & filePath) Line 286 C++ > Qt6Cored.dll!QLoggingRegistry::initializeRules() Line 327 C++ > Qt6Cored.dll!QLoggingRegistry::QLoggingRegistry() Line 275 C++ > Qt6Cored.dll!`anonymous > namespace'::Q_QGS_qtLoggingRegistry::innerFunction(void * pointer) Line 63 > C++ > Qt6Cored.dll!QtGlobalStatic::Holder<`anonymous > namespace'::Q_QGS_qtLoggingRegistry>::Holder<`anonymous > namespace'::Q_QGS_qtLoggingRegistry>() Line 74 C++ > Qt6Cored.dll!QGlobalStatic<QtGlobalStatic::Holder<`anonymous > namespace'::Q_QGS_qtLoggingRegistry>>::instance() Line 127 C++ > Qt6Cored.dll!QGlobalStatic<QtGlobalStatic::Holder<`anonymous > namespace'::Q_QGS_qtLoggingRegistry>>::operator()() Line 110 C++ > Qt6Cored.dll!QLoggingRegistry::instance() Line 444 C++ > Qt6Cored.dll!QLoggingCategory::init(const char * category, QtMsgType > severityLevel) Line 234 C++ > Qt6Cored.dll!QLoggingCategory::QLoggingCategory(const char * category, > QtMsgType enableForLevel) Line 223 C++ > Qt6Quickd.dll!QSG_LOG_INFO() Line 79 C++ > Qt6Quickd.dll!`anonymous > namespace'::QLoggingCategoryMacroHolder<0>::QLoggingCategoryMacroHolder<0>(const > QLoggingCategory &(*)() catfunc) Line 123 C++ > Qt6Quickd.dll!QSGRhiSupport::applySettings() Line 237 C++ > Qt6Quickd.dll!QSGRhiSupport::configure(QSGRendererInterface::GraphicsApi > api) Line 289 C++ > > Qt6Quickd.dll!QQuickWindow::setGraphicsApi(QSGRendererInterface::GraphicsApi > api) Line 3869 C++ > Qt6WebEngineCored.dll!initialize() Line 248 C++ > Qt6WebEngineCored.dll!`anonymous > namespace'::initialize_ctor_class_::initialize_ctor_class_() Line 250 C++ > > Qt6WebEngineCored.dll!`anonymous namespace'::`dynamic initializer for > 'initialize_ctor_instance_''() Line 250 C++ > Seems like it is UB because initialization of static variables is undefined, as I see in Qt6.5 added Q_CONSTINIT before QCoreApplicationPrivate::theMainThread declaration, but it will work only starting from c++20 standard, but is it possible to workaround it?
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest