Statically linked app with Qt gives error: Failed to load platform plugin “windows”

前端 未结 5 1663
生来不讨喜
生来不讨喜 2020-12-31 13:27

I have built Qt 5.0.1 statically in VS 2010 under Windows 7 x64. The configuration parameters were

configure -debug-and-release -opensource -confirm-license          


        
相关标签:
5条回答
  • 2020-12-31 13:50

    Just do the following steps:

    1. Go to bin folder in your Qt installation directory
    2. Copy all files with .dll extension
    3. Past them to C:\Windows\System32 for 32 bits or C:\Windows\syswow64 for 64 bits.
    4. Tada! you will never see that irritating message again
    0 讨论(0)
  • 2020-12-31 13:51

    I just had the same problem, so here is my solution:

    First of course build QT with the -static parameter.

    Add the following libs to your build:

    Qt5PlatformSupport.lib
    qwindows.lib
    imm32.lib
    

    Add the following path to your library paths:

    $(QTDIR)\plugins\platforms
    

    In your code (preferably main.cpp) add the following line:

    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
    

    The resulting build should not depend on any qt-related dlls.

    0 讨论(0)
  • 2020-12-31 13:52

    If you are using libGLESv2.dll, then you must include libEGL.dll, too. See Deploying Qt C++ Application from Visual Studio qwindows.dll error

    0 讨论(0)
  • 2020-12-31 14:03

    It's a Qt platform plugin issue. Using qt.conf resolved the problem for me on MacOS. It doesn't matter if you link Qt staticly on not.

    I tried to staticly link to libqcocoa.a (or qwindows.lib) without success. I will let you know if i succeed.

    0 讨论(0)
  • 2020-12-31 14:06

    To check what DLL are needed to deploy your application on Windows, use dependency Walker (http://www.dependencywalker.com/).

    According to the documentation page Qt for Windows - Deployment some DLL are required to deploy a Qt application on Windows platforms:

    • qwindows.dll
    • icudtXX.dll
    • icuinXX.dll
    • icuucXX.dll
    • libGLESv2.dll
    • libEGL.dll

    Depending on the compiler you use to compile the application, some other libraries may be required:

    • MSVC specific libraries:
      • msvcrXX.dll
      • msvcpXX.dll
    • MinGW specific libraries
      • libgcc_s_dw2-1.DLL
      • libstdc++-6.dll

    Note: in all these files, replace XX by the current version of the DLL on your system.

    If you didn't build Qt statically (default), you will also need Qt5 DLL depending on Qt module you use in your application. Example:

    • Qt5Core.dll
    • Qt5Test.dll
    • Qt5Network.dll
    • etc.

    All these DLL can be found in "bin" folder, under your Qt installation dir.

    EDIT

    Recently, Qt developers created a tool named windeployqt.exe which helps you to gather all required library to deploy an application:

    Usage: windeployqt [options] [file]
    Qt Deploy Tool 5.3.0
    
    The simplest way to use windeployqt is to add the bin directory of your Qt
    installation (e.g. <QT_DIR\bin>) to the PATH variable and then run:
      windeployqt <path-to-app-binary>
    If ICU, ANGLE, etc. are not in the bin directory, they need to be in the PATH
    variable. If your application uses Qt Quick, run:
      windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>
    
    Options:
      -?, -h, --help            Displays this help.
      -v, --version             Displays version information.
      --dir <directory>         Use directory instead of binary directory.
      --libdir <path>           Copy libraries to path.
      --debug                   Assume debug binaries.
      --release                 Assume release binaries.
      --force                   Force updating files.
      --dry-run                 Simulation mode. Behave normally, but do not
                                copy/update any files.
      --no-plugins              Skip plugin deployment.
      --no-libraries            Skip library deployment.
      --qmldir <directory>      Scan for QML-imports starting from directory.
      --no-quick-import         Skip deployment of Qt Quick imports.
      --no-translations         Skip deployment of translations.
      --no-system-d3d-compiler  Skip deployment of the system D3D compiler.
      --compiler-runtime        Deploy compiler runtime (Desktop only).
      --no-compiler-runtime     Do not deploy compiler runtime (Desktop only).
      --webkit2                 Deployment of WebKit2 (web process).
      --no-webkit2              Skip deployment of WebKit2.
      --json                    Print to stdout in JSON format.
      --list <option>           Print only the names of the files copied.
                                Available options:
                                 source:   absolute path of the source files
                                 target:   absolute path of the target files
                                 relative: paths of the target files, relative
                                           to the target directory
                                 mapping:  outputs the source and the relative
                                           target, suitable for use within an
                                           Appx mapping file
      --verbose <level>         Verbose level.
    
    Qt libraries can be added by passing their name (-xml) or removed by passing
    the name prepended by --no- (--no-xml). Available libraries:
    bluetooth clucene concurrent core declarative designercomponents designer gui
    clucene qthelp multimedia multimediawidgets multimediaquick network nfc opengl
    positioning printsupport qml quick quickparticles script scripttools sensors
    serialport sql svg test widgets winextras xml xmlpatterns
    
    Arguments:
      [file]                    Binary or directory containing the binary.
    
    0 讨论(0)
提交回复
热议问题