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

The QtStartUpFunction function may be called repeatedly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: Core: Other, Core: Plugins
    • Labels:
      None
    • Platform/s:
      All

      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

            Assignee:
            thiago Thiago Macieira
            Reporter:
            zccrs chen zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: