创建一个简单的应用程序 qt5.12,5.13 编译它 uwp mcvc 64 位 2017
正在尝试创建文件:
bool ret;
FILE *fp = fopen ("Name","w+"); // this command return NULL
QFile file("Name");
Ret = file. open(QIODevice::ReadWrite);
同时提交:
winrtrunner.app: QIODevice::write (QFile, "Name"): device not open
最佳答案
如果 fopen ("Name","w+")
返回 NULL
则文件无法打开。因此,当您打开并尝试使用 Qt 内容对其进行写入时,您几乎肯定会遇到错误。
您需要找出无法打开它的原因。首先,您应该在失败的 fopen
之后立即检查 errno
,或者使用 perror
以获得更具可读性的输出:
FILE *fp = fopen("Name", "w+");
if (fp == NULL) perror("Could not open file: ");
此外,您可以使用(继承的)QIODevice::errorString()
检查失败的原因 QFile.open()
:
ret = file. open(QIODevice::ReadWrite);
if (! ret) {
const auto problem = file.errorString();
// Now log problem somehow.
}
关于c++ - 无法创建 QFile(仅适用于 msvc2017 uwp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56919601/