【qt】QT中打开文件不识别中文路径的解决办法

转自:http://blog.csdn.net/m0_37906001/article/details/76672634


头文件:#include


    QString fileName = QFileDialog::getOpenFileName(NULL,"filename","","");

    QTextCodec *code = QTextCodec::codecForName("GB2312");//解决中文路径问题
    std::string name = code->fromUnicode(fileName).data();

    if(fileName.isEmpty())
    {
        return;
    }

    org = imread(name, 1);


使用Qt自带的宏来区分操作系统跨平台源码

#if defined(Q_OS_WIN32)

p->start("cmd.exe", QStringList() << "/c" << "dir");

#elif defined(Q_OS_LINUX)

p->start("ls", QStringList() << "/home/usr_name");

#endif

connect(p, SIGNAL(finished(int)), this, SLOT(readResult(int)));


你可能感兴趣的:(qt)