PDA

View Full Version : How to embed qt plugins into the executable file?



franco.amato
29th September 2021, 11:07
Good morning Qt community,
I have to modify a project where the application loads a lot of custom Qt plugins at run-time causing a significant slowdown during loading.
I would like to know if it is possible to avoid this behavior (and consequently also the slowdown) and embed the plugins into the executable at the compile time.
Thanks in advance,
Franco

d_stranz
29th September 2021, 15:44
I would like to know if it is possible to avoid this behavior (and consequently also the slowdown) and embed the plugins into the executable at the compile time.

Then they aren't really plugins, are they? Plugins are basically DLLs, and DLLs get loaded at run time. If you want to link them at compile time, then you use static libraries.

If your slowdown is because you are loading all of the plugins at once during startup, then maybe you can implement a strategy where the plugin is not fully loaded until it is actually needed (on-demand loading). For example, instead of a single plugin interface, implement two, one that does minimal initialization - just enough to load an icon or some other placeholder to show it is available, and another that loads the full plugin when its functionality is actually needed.

franco.amato
29th September 2021, 16:48
Hi,
thanx for the answer.
Yes are plugins, ui files implementing custom widgets. Is there a way to make them embedded into the binary instead of loading them dinamically?
Regards

d_stranz
29th September 2021, 17:32
ui files implementing custom widgets

I don't think you can make a "plugin" from a UI file by itself, especially if it implements a custom widget. You have to compile the UI code using UIC and MOC and build the cpp and h files that come out into your project.

Maybe I don't understand what you are trying to do. It would help to show some of the code you are using now for loading these "plugins" dynamically.