QT常见错误(中文路径等)

1.Qt中用fopen 打开带中文路径的文件失败的解决方法:

Qt中用fopen 打开带中文路径的文件失败的解决方法_fopen中文路径_小菜刀_的博客-CSDN博客

//原错误代码如下: 
FILE			*fp;  
QString	fileName = QFileDialog :: getOpenFileName(this,"请选择文件","../","*.*");
if(!fileName.isEmpty()){
    char fname[1024];
    strcpy(fname, fileName.toStdString().c_str());
    fp = fopen(fileName, "rb");
}


/
//更正代码如下:
FILE			*fp;  
QString	fileName = QFileDialog :: getOpenFileName(this,"请选择文件","../","*.*");
if(!fileName.isEmpty()){
    char fname[1024];    
    QTextCodec *code = QTextCodec::codecForName("GB2312");
    std::string name = code->fromUnicode(fileName).data();
    strcpy(fname, name.c_str());
    fp = fopen(fileName, "rb");
}

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