"QObject::~QObject: Timers cannot be stopped from another thread" message in Qt 6.8.2 plugins
-
Hello!
In Qt 6.8.2, any timer created in a plugin by calling the startTimer() function, when the program terminates, displays the console message: "QObject::~QObject: Timers cannot be stopped from another thread". In Qt 6.8.1, there is no such message. Is this a Qt 6.8.2 bug or is there something wrong with my code?Test example:
file plugin/testplugininterface.h#ifndef TESTPLUGININTERFACE_H #define TESTPLUGININTERFACE_H #include <QtPlugin> class TestPluginInterface { public: virtual ~TestPluginInterface() {} }; #define TestPluginInterface_iid "com.MyCompany.TestPlugin.TestPluginInterface" Q_DECLARE_INTERFACE(TestPluginInterface, TestPluginInterface_iid) #endif // TESTPLUGININTERFACE_H
file plugin/testplugin.h
#ifndef TESTPLUGIN_H #define TESTPLUGIN_H #include <QObject> #include <QtDebug> #include "testplugininterface.h" class TestObject : public QObject { Q_OBJECT public: TestObject(QObject *parent = nullptr) : QObject(parent) { qDebug() << "TestObject::TestObject()"; startTimer(1000); } virtual ~TestObject() { qDebug() << "TestObject::~TestObject()"; } protected: virtual void timerEvent(QTimerEvent *event) { qDebug() << "TestObject::timerEvent"; } }; class TestPlugin : public QObject, TestPluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "com.MyCompany.TestPlugin.TestPluginInterface") Q_INTERFACES(TestPluginInterface) public: TestPlugin() : QObject() { TestObject *object = new TestObject(this); startTimer(1000); } virtual ~TestPlugin() { qDebug() << "~TestPlugin()"; } protected: virtual void timerEvent(QTimerEvent *event) { qDebug() << "TestPlugin::timerEvent"; } }; #endif // TESTPLUGIN_H
file plugin/CMakeLists.txt
set(TARGET testplugin) add_library(${TARGET} SHARED testplugin.h ) target_link_libraries(${TARGET} PRIVATE Qt::Core )
file testapp/main.cpp
#include <QApplication> #include "testwidget.h" int main(int args, char **argv) { QApplication app(args, argv); TestWidget w; w.show(); return app.exec(); };
file testapp/testwidget.h
#ifndef TESTWIDGET_H #define TESTWIDGET_H #include <QWidget> #include <QPluginLoader> #include <QtDebug> #include "testplugin.h" class TestWidget : public QWidget { Q_OBJECT public: TestWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) :QWidget(parent, f) { QPluginLoader loader("../plugin/testplugin.so"); TestPluginInterface *pluginInterface = qobject_cast<TestPluginInterface *>(loader.instance()); if (!pluginInterface) { qDebug() << "Plugin is not loaded:" << loader.errorString(); } } virtual ~TestWidget(){} }; #endif //TESTWIDGET_H
file testapp/CMakeLists.txt
set(TARGET testapp) add_executable(${TARGET} main.cpp testwidget.h ) target_include_directories(${TARGET} PRIVATE ../plugin ) target_link_libraries(${TARGET} PRIVATE Qt::Widgets )
root CMakeLists.txt
cmake_minimum_required(VERSION 3.9) project(Tests LANGUAGES CXX) set(CMAKE_AUTOMOC ON) find_package(Qt6 REQUIRED COMPONENTS Core Widgets ) add_subdirectory(plugin) add_subdirectory(testapp)
-
QPluginLoader
doesn't use a separate thread.
It's unclear to me, where exactly the error occurs, i.e. which debug statements are hit before and after.
Both objects start a timer upon construction, in the thread that constructs them.
You're not playing around with threads, so it looks to me as if the error message is bogus.
I can't reproduce it, however (macOS arm64).
Which OS are you using? -
Run your app in a debugger with QT_FATAL_WARNINGS env var set and look at the backtrace to see where it comes from.
-
QPluginLoader
doesn't use a separate thread.
It's unclear to me, where exactly the error occurs, i.e. which debug statements are hit before and after.
Both objects start a timer upon construction, in the thread that constructs them.
You're not playing around with threads, so it looks to me as if the error message is bogus.
I can't reproduce it, however (macOS arm64).
Which OS are you using?@Axel-Spoerl said in "QObject::~QObject: Timers cannot be stopped from another thread" message in Qt 6.8.2 plugins:
Which OS are you using?
Linux (Ubuntu and Debian).
Thanks for the answers. I reported the bug and am waiting for a solution.
https://bugreports.qt.io/browse/QTBUG-134080 -
QT has a thread that processes the events, and this error indicates that your program is forcing QT to reparse the events.
Why does your class extend public QObject? And you decorated the class with Q_OBJECT.
If I were you, I would remove the public QObject and re-test