qt5 打开中文路径的图片时失败了,使用下面三行代码也不行:
QTextCodec::setCodecForTr(...) QTextCodec::setCodecForCStrings(...) QTextCodec::setCodecForLocale(...)后来尝试了一下先将QString通过 toLocal8Bit()转换成QByteArray,最后再转换成std::string,可以正常工作。代码如下:
void LoadImageFromPath(){QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral("Load Image"),"C:/Users/qiuqiang/Desktop",tr("Images (*.ppm *.png *.bmp *.jpg *tif)"));if(fileName.size()>0){cv::Mat img = cv::imread(fileName.toLocal8Bit().toStdString() , 0);if (!img.empty()){
//img.copyTo(m_src);//ui->lb_debug->setText(fileName);}
else//ui->lb_debug->setText(QStringLiteral("Load Image failed"));}
}