1

当我尝试在另一台计算机上执行我的 qt 程序时,我收到此错误并崩溃:

Failed to load platform plugin "windows". Available platforms are:
windows

我知道这个问题已经在其他几个问题中讨论过:

无法加载平台插件“windows”可用的平台是:windows、minimal

Qt 应用程序:无法加载平台插件“windows”。可用平台有:

PyQt5 - 无法加载平台插件“windows”。可用平台有:windows、minimal

但是我已经应用了建议的解决方案,但它仍然对我不起作用。相关信息:

  • 我使用 Qt 5.1.0 和 MinGW 4.8 32bit 进行开发

  • 在我的开发电脑(Win7、64 位)上,程序执行得很好

  • 我在发布模式下编译了我的应用程序

  • 目标电脑 (Win7, 32bit) 没有安装 Qt

  • 我的 .pro 的一部分:

    QT += core gui opengl network xml testlib

    目标 = 我的应用

    模板 = 应用程序

    配置 += qtestlib 帮助

    配置 -= app_bundle

  • 我的部署文件夹的内容:

    我的应用程序

    [所有 dll,在我的开发环境的 .exe 文件夹中]

    [来自 Qt/5.1.0/5.1.0/mingw48_32/bin 的所有 dll]

    [来自 Qt/5.1.0/Tools/mingw48_32/bin 的所有 dll](包括 libEGL.dll、libEGLd.dll、libGLESv2.dll、libGLESv2d.dll)

    [来自 Qt/5.1.0/Tools/QtCreator/bin 的所有 dll]

    平台/qwindows.dll

4

1 回答 1

0

我对 qwindows.dll 有同样的问题——win7 64 ok,win7 32 失败,无法找到 qwindows.dll

首先我检查了我可以用-platformpluginpath运行它:

app.exe -platformpluginpath plugins/platforms 

一切正常,所以问题只是应用程序内的搜索路径错误。最后我只添加了所有可能的路径:

#include <QApplication>
#include <QDir>

void registerPluginsDir(QDir& exeDir)
{
#ifdef Q_OS_MAC
        QString pluginsRelPath = "/../../PlugIns";
#elif defined(Q_OS_WIN)
        QString pluginsRelPath = "Plugins";
#elif defined (Q_OS_LINUX)
        QString pluginsRelPath = "../lib/plugins";
#else
       #error "Unsupported OS"
#endif

    QString platformsRelPath = "platforms";
    QString pluginsPath = exeDir.absoluteFilePath(pluginsRelPath);
    QString platformsPath = QDir(pluginsPath).absoluteFilePath(platformsRelPath);
    QStringList pathes = QCoreApplication::libraryPaths();
    pathes << pluginsPath;
    pathes << platformsPath;
    pathes << platformsRelPath;
    pathes << pluginsRelPath;
    QCoreApplication::setLibraryPaths(pathes);
}

int main(int argc, char *argv[])
{
    QString exePath = QString::fromUtf8(argv[0]);
    QFileInfo exeInfo (exePath);
    QDir exeDir (exeInfo.absolutePath());

    //need to set correct plugins path before app instance created
    registerPluginsDir(exeDir);

    QApplication app(argc, argv);
    // more code here

    return app.exec();
}
于 2014-01-21T11:18:32.483 回答