Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "QObject::~QObject: Timers cannot be stopped from another thread" message in Qt 6.8.2 plugins
Forum Updated to NodeBB v4.3 + New Features

"QObject::~QObject: Timers cannot be stopped from another thread" message in Qt 6.8.2 plugins

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 365 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Serg Mueller
    wrote on last edited by
    #1

    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)
    
    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #2

      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?

      Software Engineer
      The Qt Company, Oslo

      S 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Run your app in a debugger with QT_FATAL_WARNINGS env var set and look at the backtrace to see where it comes from.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • Axel SpoerlA Axel Spoerl

          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?

          S Offline
          S Offline
          Serg Mueller
          wrote on last edited by Serg Mueller
          #4

          @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

          1 Reply Last reply
          4
          • C Offline
            C Offline
            clopez
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved