我的程序是这样的,一个主程序(QtCreator创建,工程中的所有文件使用UTF-8编码),调用
QFileDialog获取文件路径。
另一个动态库工程(QtCreator创建,工程中的编码使用GBK编码),动态库中的一个类提供ReadFile(const char* strpath)接口。
动态库中定义:void DLLClass::ReadFile(const char* strpath)
{
QString strp;
strp.fromLatin1(strpath); //错误出现了,这里strp为空,不知道为什么
}
现在调用方式如下:QString strpath = QFileDialog::getOpenFileName(this,tr("选择文件"),QDir::currentPath());
DLLClass sl;
sl.ReadFile(strpath.toLatin1().constData(); //这里的转换应该是有效的
多谢赐教!!!
[ 此帖被rojer在2010-08-06 10:13重新编辑 ]