windows 环境,QProcess传参 argv 解析中文目录乱码问题解决。

#include 
#include 
#include 
#include 
#include 

using namespace std;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
#endif
  
	//使用QCoreApplicationo类方法获取进程参数,解决中文路径解析出错的问题。
    QString strPath = a.arguments().at(1);
    cout << "filepath:" << strPath.toStdString();
    QFile file(strPath);
    if (file.open(QIODevice::WriteOnly | QIODevice::Append)) {
        cout << "open file success!" << std::endl;
        file.write(qApp->arguments().at(2).toLocal8Bit());
    } else {
        cout << "Error! " << file.errorString().toStdString();
    }

    file.close();
    return a.exec();
}

你可能感兴趣的:(Qt,Creator,Windows,qt,c++,windows)