How to compile a standalone executable

  • Firstly, thank you for the excellent QT. I have enjoyed using it for personal projects.
    Secondly, can someone tell me how I can display the full text windows when composing a message? I can see only the first 3 lines or so and the box then disappears below the bottom of the browser window. It can’t be scrolled up!
    Now for the real reason for my post. How do I create an executable that I can use on another Windows computer without getting messages telling me that various DLLs are missing?
    I have added the following to the .pro file:
    CONFIG += static

    But this did not make any difference. I found a so-called tutorial page about building static binaries and was horrified that it starts with re-compiling the QT program! This is utterly unbelievable! This should be a simple configuration option. Dismayed and incredulous, I gave it a try anyway, only all of the commands I typed were met with ‘command not found’. Where do I need to type them? The documentation seems to be written from the point of an advance user in the know and doesn’t make much sense from a beginner perspective. I tried both in a windows command prompt and by going to the Mingw Desktop. I am using QT 5.8.0 with Mingw as I want to build my current project as a cross-platform application.

    Could someone tell me what the difference is with the newer Visual Studio variants? I understand that Visual Studio can only build Windows binaries and I intend to continue cross- platform development, but the mingw variant of QT is 32 bit only? Why? A 64 bit mingw has been around for quite some time.

    I have also tried using Cmake and Cmakefile.txt files, as this is what I did several years ago which worked well. I have not used it for a while but this has also proved problematic as bits of QT seem to be missing (e.g. I found the cmake files and specified the path, but am being told that no modules have been installed).

    I have just spend a frustrating two hours trying to find a way forward, so if anyone can help me get started with this it would be appreciated. Do I really need to re-compile the compiler to build standalone programs?

  • Hi,

    Basically, you have only 2 options:

    • Deploy all Qt dlls required for your executable alonside with it. There is a tool windeployqt that can help you, though note that it might add more dlls than you really need to stay on the safe side.
    • Use static build, but you really need to build Qt yourself to do this, there are no official static builds of Qt.

  • Thank you for the response. I have already looked at windeployqt which is helpful, but it copies around 600mb of DLLs into the executable program directory which seems rather excessive for my fairly small program! Other than the LCD control, I am using only 'standard' QT controls - text boxes, combos, labels etc - nothing special.
    I was surprised that in order to build static binaries it is necessary to build a separate static version of QT. In any programming environment I have used, it is usually a simple matter of configuration or switches. However, thanks for confirming that. The question now is, where do I enter the commands that were mentioned in the tutorial here:
    They do not work from the Windows command line?
    This morning I found another page on the subject here using a powershell script:
    I will try and follow this and see what happens.
    PS, can someone fix the editor box so that we can see what we are posting beyond a few lines? The bottom of the box is missing so I am having to type this into a text editor and then copy+paste into the online editor to submit. Thanks.

  • @Qcontinuum said in How to compile a standalone executable:

    I have already looked at windeployqt which is helpful, but it copies around 600mb of DLLs into the executable program directory which seems rather excessive for my fairly small program!

    are you sure, you try to deploy a release build and not a debug build?
    DLL's needed for a debug build are significantly larger than their release counterpart.

  • Moderators

    @Qcontinuum 600MB is definitely too much! Can you tell us what is inside the deployment directory? Is it debug or release build?

  • Yes I had done a debug build. I have just performed a release build and the directory resulting from windeployqt is now 41.6mb in size. Much better! Thank you. Its a while since I did any serious development and should have realised that this would be the issue.

  • PS, there is still an issue though. When I run the program on another PC, the fonts on buttons and controls are significantly larger than in the development environment such that the text no longer fits on the buttons and affects the layout of the application. Any ideas why this should be? GUI controls are built using the design tool and are using the default 'Ms Shell Dlg 2' font. Both development and target PC are Windows 7. Haven't tried it on Windows 10 yet.

  • @Qcontinuum Well, a few things come to mind.

    • is the target display resolution smaller than your develop environment
    • is the target display a High DPI Display?
    • differ the target and develop pc the windows textsize?

  • The display on the target machine is bigger and does have a higher resolution. I don't think its a high DPI display though. However, the text size was indeed different. It was set to 'Medium', i.e. 125% of default. Setting it back to 'Smaller' i.e. 100% solved the problem.

    Curious that other applications are not affected in the same way though?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.