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

The QtStartUpFunction function may be called repeatedly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 5.15.2
    • Core: Other, Core: Plugins
    • None
    • All
    • 22e967c3049608f82abd32a0beb0b4b36ee134bf

    Description

      When I tried to use Q_COREAPP_STARTUP_FUNCTION(test_qAddPreRoutine) in the Qt platforms plugin, I found that the test_qAddPreRoutine function would be called twice.

      #include <qpa/qplatformintegrationplugin.h>
      #include <qpa/qplatformintegration.h>
      #include <private/qgenericunixeventdispatcher_p.h>
      #include <QCoreApplication>
      #include <QDebug>
      
      static void test_qAddPreRoutine() {
          qDebug() << Q_FUNC_INFO;
      }
      Q_COREAPP_STARTUP_FUNCTION(test_qAddPreRoutine)
      
      class Test : public QPlatformIntegration {
      public:
          QPlatformBackingStore *createPlatformBackingStore(QWindow *) const override  {
              return nullptr;
          }
          QPlatformWindow *createPlatformWindow(QWindow *window) const override {
              return nullptr;
          }
          QAbstractEventDispatcher *createEventDispatcher() const override {
              return createUnixEventDispatcher();
          }
      };
      
      class TestPlugin : public QPlatformIntegrationPlugin {
          Q_OBJECT
          Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "test.json")
      public:
          QPlatformIntegration *create(const QString&, const QStringList&, int &, char **) override {
              return new Test();
          }
      };
      
      #include "main.moc"
      

      If application load the “test” platform plugin, can get two lines output:

      log

      void test_qAddPreRoutine()
      void test_qAddPreRoutine()

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            zccrs JiDe Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: