版本,QTcreator5.6.2
首先在头文件中添加#include <QTextCodec>
直接上代码:
QString fileName=QFileDialog::getOpenFileName(this,tr("Open Image"),".",tr("Image Files(*.png *.jpg *jpeg *.bmp *.avi *.mp4)"));
QTextCodec *code = QTextCodec::codecForName("GB2312");//解决中文路径问题
std::string name = code->fromUnicode(fileName).data();
if(fileName.isEmpty())
{
return;
}
inputVideo.open(name);//我准备打开的是本地视频文件