Qfile open returns false
Qfile open returns false
我将Content.xml
保存在我的app.exe
存在的文件夹中。
但是open call返回false ?
文件的确切路径应该是什么?
我不想给出文件的完整路径,但希望我的代码是路径独立的"意味着我想要读取的文件应该在我的exe所在的文件夹中"
#define FILE_NAME "Content.xml"
QString xmlFileName(FILE_NAME);
xmlFile.setFileName(xmlFileName);
if ( ! xmlFile.open(QIODevice::ReadOnly|QIODevice::Text) )
{
QMessageBox* msgBox = new QMessageBox();
msgBox->setText("File Not Found !!");
msgBox->setWindowFlags(Qt::WindowStaysOnTopHint);
msgBox->exec();
}
尝试使用完整路径打开文件,如:
xmlFile.setFileName(QCoreApplication::applicationDirPath() + QLatin1Char('/') + xmlFileName);
如果您使用Qt Creator中的运行按钮运行代码,则Content.xml需要与您的代码在同一文件夹中
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 伪造事实↔false
- QueryWorkingSet总是返回false
- 如何区分地图中的 0 和 false?
- 模板参数列表中的 false 在模板初始化期间计算为什么?
- Arduino-C++ bool 不会从 false 变为 true
- 当返回类型声明为 ListNode 时,我们是否可以返回 false<T>*
- 当我的 if 条件计算结果为 false 时,我的 else 块将不会执行
- 等于在 c++ 中返回 false
- strcmp 对于相等的字符序列返回 false
- std::is_class 在引用类上为 false
- ios_base::sync_with_stdio(false); cin.tie(NULL);
- CreateWICTextureFromFile returns E_NOINTERFACE
- C++ - 负数和正数之间的比较返回 false
- 如何使用boost定义布尔类,可能的值应该是TRUE或FALSE?
- 如何编写一个接受如下断言消息的自定义断言函数:assert(false) << "assertio
- QSslSocket and supportsSsl() returns false
- setData returns false for QAbstractProxyModel
- Qfile open returns false
- QLibrary resolve returns false