1、如果指定路径下,创建文件,要保证指定的路径不要有中文。
2、如果有中文的话会因为路径有中文而创建失败
3、解决办法:使用 QString::fromLoacl8Bit(“输入你的含有中文的路径”);
void XML_2::_CreateXml_file() //创建xml文件
{
QString _xmlfile = QString::fromLocal8Bit("E:/QT-VS_testt/test17_VS_Qt_xml学习/xml_2") +"/xml2_test.xml";
QFile _xmlFile(_xmlfile);
if (!_xmlFile.open(QIODevice::ReadWrite))
{
qDebug() << QString::fromLocal8Bit("xml文件创建失败!");
}
else {
qDebug() << QString::fromLocal8Bit("xml文件创建成功!");
qDebug() << _xmlfile;
}
_xmlFile.close();
}
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/270492.html