Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can make .exe file in qt5 for windows and linux?



  • Hi everyone!
    I am using an ubuntu machine for the development of the qt application but now I need to make a .exe file that can also run on the Windows operating system. Firstly how I can make a .exe file in Linux then how it can be deployed on windows.
    Thanks!


  • Lifetime Qt Champion

    Hi,

    If you want to build an executable for Windows on Linux you will need to cross-compile using MinGW. Depending on the libraries you are using you'll need to cross-compile them as well.

    As for the deployment, you can use Qt's installer framework or another similar tool of your choice.

    Note that it will likely be easier to setup a virtual machine with Windows and compile natively there. This will also allow you to check that your application works correctly on that OS.



  • @SGaist Thanks for your reply! How I can make .exe on Linux?



  • @SGaist If I will set up a virtual machine on windows os and try the application developed on ubuntu is it your means?


  • Lifetime Qt Champion

    @Mijaz said in How can make .exe file in qt5 for windows and linux?:

    If I will set up a virtual machine on windows os and try the application developed on ubuntu is it your means?

    You set up a virtual machine with Windows, install Qt and a compiler there and build your app for Windows there.
    This is way easier than setting up a cross compile environment on Linux to build for Windows.



  • @jsulm Is generated .exe on windows using VMWARE will run always without starting VMWARE? Is it possible?


  • Lifetime Qt Champion

    @Mijaz said in How can make .exe file in qt5 for windows and linux?:

    Is generated .exe on windows using VMWARE will run always without starting VMWARE?

    Of course. It does not matter whether you run an OS like Windows in a virtual machine or not. That is the whole point of virtualization.



  • @jsulm Thanks! But if I need to cross-compiled then what I should have to do for compilation? Kindly give your best remarks on the cross compilation?


  • Lifetime Qt Champion

    @Mijaz I never cross compiled from Linux to Windows. You should check MinGW documentation if you really want to to go this route (I again want to point out that setting up a virtual machine with Windows is WAY easier than setting up a cross compile environment).



  • You can set up a VM and compile and build it on windows then just take out that .exe file in your build directory and put it in an empty folder then open those compiler-command prompt stuff(i'm new so i dont know what they're called)d117e3d0-91fa-480f-8353-4a4f0d15bfd6-image.png
    and type in windeployqt your_exe_filename.exe, it will build it, that's how i do mine, if your app uses QML then u write windeployqt --qmldir your_exe_name.exe
    136007ef-5e20-41fc-9edf-a83a04e836cd-image.png



  • Qt is not Java. Java is built once and can be run everywhere. For Qt, you use the same code, but have to build your apps on different platforms(Windows, Linux, MacOS) separately to make the executables.



  • I'll deviate a bit from consensus above: use a hosted CI environment.
    Even for closed sources, GitHub now offers Actions for free that is able to build, test and create release packages for every platform.
    It's soooooooooo much easier than setting up and maintaining your VMs.

    Alternatives:


Log in to reply