After running windeployqt qcanbus::instance()->plugins() returns an empty list in a static instance
-
Hello, I have been running into a weird issue with windeployqt and static initialization.
I have a class Bservice that has a static member of another class, DeviceManager. BService.h looks something like this:
class BService : public QObject { public: static DeviceManager devManager; }
BService.cpp looks something like this:
#include "bservice.h" DeviceManager BService::devManager; BService::BService(QString portName, QObject * parent) : QObject(parent) { }
In DeviceManager, I have a method that gets all of the devices from all available CAN plugins. It first calls
QCanBus::instance()->plugins()
and stores it into a QStringList.
Before running windeployqt.exe, the QStringList has all of the available plugins. After running windeployqt, it install the necessary .dll's(specifically QT6Core.dll) into the build directory. Next time I run the program, when it gets to the plugins line, the QStringList is empty. In debugger I can see that this is getting called by _static_initialization_and_destruction_0
I have found that removing QT6Core.dll from the build directory and running again then the plugin list is full of the available plugins.
Having QT6Core.dll in the build directory and removing the static keyword from DeviceManager and commenting out the constructor for DeviceManager above the BService.cpp class allows other non static devicemanager objects to read the plugins.
If both QT6Core.dll is in the build directory and DeviceManager is static, then any other DeviceManager(not static) objects in my program do not get any plugins.
In the build directory I can see the canbus folder and in the folder are the dll's for all of my canbus plugins.
My guess is that QCanBus is not getting statically initialized.
Any help is appreciated, I have been trying to tackle the problem for the past few days and have done hours of googling. If I have missed some context just let me know and I'll update this post.
Thanks in advance,
Eric