判断文件是否存在。
路径是固定的:"./xml./monitor"文件夹内
文件名称可变的,定义为QSring monitor_name;
用if (!QFile::exists())判断文件是否存在,我写完QFile file(":/xml/monitor/monitor_name");但文件命名不对,困扰好长时间了,帮忙啊。
------解决方案--------------------
QFile file(":/xml/monitor/monitor_name");不对吧
应该是QFile file(":/xml/monitor/" + monitor_name);吧
------解决方案--------------------
哈哈。。我估计也是这个。。
------解决方案--------------------
QString dir("./xml./monitor"); //注意路径写准确
QString monitor_name;
//中间再写入给变量monitor_name赋值的语句
qDebug()<<QFile::exists(dir+monitor_name);
------解决方案--------------------
QString monitor_name; //monitor_name是路径+文件名的格式,如D:/helloworld.txt
QFile f(monitor_name);
qDebug()<<f.exists();
这是第二种写法,输出true则文件存在,输出false则不存在
------解决方案--------------------
QFile file(":/xml/monitor/monitor_name");
为什么是 “:”?
------解决方案--------------------
QFile file(":/xml/monitor/monitor_name");
为什么是 “:”?
应该是QFile file("./xml/monitor/monitor_name");吧
------解决方案--------------------
顶2楼啊啊啊