有如下成员函数:
void PicBox::openImg()
{
QString srcpath = QFileDialog::getOpenFileName(this, "choose a image file", "", "Image File(*.jpg;*.png;*.bmp;*.tiff;*.tif)");
if (srcpath.isEmpty())
return;
//qDebug() << srcpath.toUtf8().data();
this->setImg(cv::imread(std::string((const char *)srcpath.toLocal8Bit())));
// cv::imshow("",cv::imread(srcpath.toStdString(), cv::IMREAD_LOAD_GDAL));
}
std::string((const char *)srcpath.toLocal8Bit()));用于转换字符编码,cv::imread() 函数只可以读入std::string
//std::string((const char *)srcpath.toLocal8Bit()));用于转换字符编码,cv::imread() 函数只可以读入std::string//也可以使用//std::string(srcpath.toLocal8Bit().data()));