c++ - 无法创建 QFile(仅适用于 msvc2017 uwp)

标签 c++ qt uwp qt5

创建一个简单的应用程序 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/

相关文章:

c++内联函数在GCC内联汇编中包装单个vmovups

c++ - std::max_element() 有多聪明?

c# - 单击后放大图像 C# UWP

c++ - QT 5 中的 QUrl 解析

visual-studio-2010 - 为 Visual Studio 2010 构建 Qt - 无法打开文件 'qtmaind.lib'

c# - Xamarin Forms UWP - 无法为 .NET Native 工具链编译

c# - 如何从 UWP 中的 IBuffer 或字节数组创建 IDirect3DSurface

c++ - 编写一个简单的 Bootloader HelloWorld - 错误函数打印字符串

c++ - 在 GTest 中,如何检查非常接近 0 的数字? EXPECT_FLOAT_EQ 不工作

c++ - 从 Qt 5.6 切换到 Qt 5.7 - 命名空间 std 中的 "no member ' make_unique'