You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Qt Creator获取.exe输出?Mac环境生成Windows可运行.exe方法

Hey there, let's tackle both of your questions clearly—since the second one is a cross-compiling scenario (Mac to Windows), it's a bit more involved, but totally doable.

1. Getting a .exe from Qt Creator (Windows Native)

If you're working directly on a Windows machine with Qt Creator, here's the straightforward process:

  • First, make sure you have the Windows version of Qt installed (either with MinGW or MSVC compiler—MinGW is easier for quick distribution).
  • Open your project, then in the bottom-left corner of Qt Creator, switch to the Release build profile (skip Debug mode—those exes rely on debug libraries and won't run on non-development machines).
  • Click the build button (the hammer icon) to compile your project. Once done, your raw .exe will be in the release subfolder of your project directory (for MSVC, it might be in x64/Release or similar, depending on your architecture).
  • This raw exe won't run on other Windows PCs yet—it needs Qt's dependency libraries. Fix this with the windeployqt tool:
    1. Open the Qt Command Prompt matching your compiler (e.g., "MinGW 64-bit Prompt")
    2. Navigate to the folder where your .exe is stored
    3. Run: windeployqt your_app_name.exe
  • This tool will automatically copy all required DLLs, Qt modules, and resource files into the same folder. Now you can zip up the entire folder and share it—any Windows PC can run it.
2. Cross-Compiling a Windows .exe from Qt Creator on Mac

Generating a Windows-compatible exe from a Mac requires setting up a cross-compilation toolchain. Here's the step-by-step:

  • Step 1: Install the cross-compiler
    Use Homebrew (if you don't have it, install it first) to get the MinGW-w64 toolchain for Windows targets. Open Terminal and run:
    brew install mingw-w64
    
  • Step 2: Configure a Windows Kit in Qt Creator
    Qt Creator needs a dedicated kit to cross-compile for Windows:
    1. Go to Tools > Options > Kits
    2. Click Add to create a new kit, name it something like "Windows 64-bit (MinGW Cross)"
    3. Under the Compiler tab:
      • For C compiler, select x86_64-w64-mingw32-gcc (it should show up after installing mingw-w64)
      • For C++ compiler, select x86_64-w64-mingw32-g++
    4. Under the Qt Version tab:
      • You need a Windows-compatible Qt library (not the Mac one!). Open the Qt Maintenance Tool, and add a Qt version like Qt 5.15.2 > MinGW 8.1.0 64-bit (match the MinGW version from your cross-compiler if possible)
      • Browse to the qmake executable of this Windows Qt installation (e.g., ~/Qt/5.15.2/mingw81_64/bin/qmake) and add it to Qt Creator
    5. Save the kit—you're now ready to cross-compile.
  • Step 3: Build your project for Windows
    • Open your sample project in Qt Creator, then switch to your new Windows kit in the bottom-left corner, and select Release mode
    • Click the build button. Once finished, your Windows .exe will be in the build directory (look for a folder named something like build-YourProject-Windows-Release)
  • Step 4: Package dependencies for distribution
    You can't run windeployqt natively on Mac for Windows exes easily, so two reliable options:
    1. Use a Windows machine: Copy the .exe to a Windows PC, open the Qt Command Prompt there, run windeployqt your_app.exe to gather all dependencies.
    2. Use cross-compiled windeployqt on Mac: Locate the windeployqt from your Windows Qt installation (e.g., ~/Qt/5.15.2/mingw81_64/bin/windeployqt), then run:
      ~/Qt/5.15.2/mingw81_64/bin/windeployqt --dir ./deploy your_app.exe
      
      This will copy most Qt dependencies to a deploy folder. You'll also need to add a few system DLLs from your mingw-w64 installation, like libgcc_s_seh-1.dll, libstdc++-6.dll, and libwinpthread-1.dll—find them in /usr/local/opt/mingw-w64/x86_64-w64-mingw32/bin and copy them into the deploy folder.
  • Zip up the deploy folder with your exe, and it'll run on any Windows PC.

Quick Notes to Avoid Headaches

  • Always use Release mode for distributable exes—Debug builds are for development only.
  • Make sure your Qt version matches the MinGW cross-compiler version (e.g., MinGW 8.1 with Qt built for MinGW 8.1) to avoid linker errors.
  • If your project uses third-party libraries, you'll need to cross-compile those for Windows too, or use pre-built Windows versions that match your toolchain.

内容的提问来源于stack exchange,提问作者Mahdiyar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:02:28