首页 > 代码库 > QT5 Failed to load platform plugin "windows" 终极解决方案 命令行问题

QT5 Failed to load platform plugin "windows" 终极解决方案 命令行问题

Failed to load platform plugin "windows"

 这个错误在双击exe执行时不会出现,当传递命令行参数时出问题 ,解决方法:

int main(intargc,char *argv[])

{
    Q_INIT_RESOURCE(rc);
//解决库路径问题============info@seatrix.com
    QTextCodec *xcodec = QTextCodec::codecForLocale() ;
    QString exeDir = xcodec->toUnicode( QByteArray(argv[0]) ) ;
    QString BKE_CURRENT_DIR = QFileInfo(exeDir).path() ;
    QStringList  libpath;
    libpath << BKE_CURRENT_DIR+QString::fromLocal8Bit("/plugins/platforms");
    libpath << BKE_CURRENT_DIR <<BKE_CURRENT_DIR+QString::fromLocal8Bit("/plugins/imageformats");
    libpath << BKE_CURRENT_DIR+QString::fromLocal8Bit("/plugins");
    libpath << QApplication::libraryPaths();
    QApplication::setLibraryPaths(libpath) ;
//=========================
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

QT5 Failed to load platform plugin "windows" 终极解决方案 命令行问题