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

Library initialization function crashes on win when called from loading QML plugin

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.0
    • 5.11.1
    • None
    • * Window 10 1803
      * MSVC 2017
      * Qt 5.11.1
    • Windows

    Description

      Assuming we have 3 projects. The first is a dynamically linked library that has a Q_COREAPP_STARTUP_FUNCTION that registers a type. The second one is a QML-Plugin that depends on the previous library and itself registers a type. The third is a QtQuick app that loads the plugin, but does not directly depend on the library.

      What happens is that when trying to run the application, it fails to load the qml plugin with the error message (text freely translated from german)

      QQmlApplicationEngine failed to load component
      qrc:/main.qml:3 plugin cannot be loaded for module "com.example.plugin": The library E:\build-PluginBug-Desktop_Qt_5_11_1_MSVC2017_64bit-Debug\qml\com\example\plugin\qmlplugin.dll could not be loaded: A DLL initialization routine failed.
      

      Further debugging shows, that the application crashes inside the previously registered Q_COREAPP_STARTUP_FUNCTION inside the qmlRegisterType method! (Stacktrace attached) The curser shows that it crashes when trying to access the static meta object from the QML_GETTYPENAMES macro.

      Whats strange about this issue is that this only happens when the main application does not directly depend to the library, i.e. it is loaded only on demand when loading the plugin. Directly linking the app to the lib does not trigger that exception, as the initialization code is loaded before entering the main and not from within the plugin loading. This only happens on windows. Testing on linux shows that loading works completley fine, even indirectly.

      A sample project was attached to this issue. You can uncomment Line 5 in app/app.pro and rebuild the project to switch between the indirect loading (only plugin depends on dll) or the direct loading (app and plugin depend on dll).

      Attachments

        1. PluginBug.zip
          5 kB
        2. stacktrace.txt
          10 kB

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              SkyCoder Felix Barz
              Maurice Kalinowski Maurice Kalinowski
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes