Adding executables as Qt application resources?

I have an external command line executable program "program.exe" that uses the DLL "program.dll". I would like to insert these two files as resources in my Qt application. Then later I will need to run program.exe from my application. Can this be done with Qt? In particular, can executables and DLLs be added as resources?

+3


source to share


3 answers


You can add them as resources, but you cannot execute your "program.exe" directly from the resource, and this is a pure Qt system that the underlying OS will not understand.

What you need to do at runtime is copy it (with .dll) from resources to a temporary location and execute from there.



Obviously, as @webclectic pointed out, this is not the correct approach. If there is no good reason to do so, the correct way is to package (.msi, .rpm depending on the target OS) with these executables and deploy them that way.

+3


source


In particular, can executables and DLLs be added as resources?

Yes, they can, if you add the executable to the qrc file, you will notice that the size of your Qt application will grow by the size of the added resource executable.



But do you really want to do something like this? I've never tried to do something like this, but I doubt it's possible. The system will not be able to read the executable from your resources. The execution of the executable is system specific and the system must be able to find the executable. I believe that when you start the application, you can copy the executable to a temporary directory and call it from there. You must delete these files when the application exits.

Personally, I will not follow this approach. Its much easier and elegant (IMHO) to create an installer that would copy all the required executables / DLLs into the application folder.

+3


source


Binary resources can be added as resources, and like others, they have been extracted to a temporary location to be executed from there. This is similar to how self-extracting installers work.

However, you can also use them directly without storing them in a temporary location by writing out a custom DLL loader.

I'm not sure, but I think executables can be loaded the same way and run by markup. But I think the resulting process will be different compared to when it is started directly from the hard drive.

I've seen application source code that does exactly that, however it is non-trivial and requires knowledge of low level material. If anyone has good resources on how to do this, please add them.

0


source







All Articles