Qt 不能创建/写入 C :\

标签 qt qfile

我正在编写一个 Qt 程序(最初为 Windows 7 为 4.7),它需要写入已安装的目录(C:\Program Files...)。当我尝试写入一个“ protected ”的位置(程序文件、C:\等)时,没有创建任何文件。但是,QFile 没有给我任何错误代码(error() 返回 0,这意味着它工作正常)。

这是我正在使用的代码片段,但它不起作用。我在程序中稍后关闭文件。

QApplication a(argc, argv);

// Setting plugin paths.
QStringList paths = QCoreApplication::libraryPaths();
paths.append(QCoreApplication::applicationDirPath());
QCoreApplication::setLibraryPaths(paths);



// Debug file.
QString path = QCoreApplication::applicationDirPath() + "/debug.dat";
//QFile debugFile(QCoreApplication::applicationDirPath() + "/debug.dat");
QFile debugFile("C:/debug.txt");
qDebug() << debugFile.error();
debugFile.setPermissions(QFile::WriteUser | QFile::WriteGroup | QFile::WriteOwner | QFile::WriteOther);
debugFile.open(QFile::WriteOnly);
QTextStream debugStream(&debugFile);

// Processing the arguments.
debugStream << QString("Processing Arguments\n");

有没有人有关于如何解决这个问题的任何提示?

谢谢您的帮助,

jack

添加 list 文件是我选择解决此问题的途径。

感谢所有的帮助。

最佳答案

您是否检查过该文件是否未在 VirtualStore 中为该用户创建?检查应用程序和服务日志 -> Microsoft -> Windows -> UacFileVirtualization -> Operational 下的事件查看器。如果您看到事件 ID 为 5000 的条目,则表示发生了 FileCreateVirtualExclude 事件。

检查文件是否未在 %USERPROFILE%\AppData\Local\VirtualStore 下创建.如果是这样,您可能需要嵌入请求所需权限的 list (即关闭虚拟化)。

更多详情请见New UAC Technologies for Windows Vista (向下滚动并查找虚拟化。)

关于Qt 不能创建/写入 C :\,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4640730/

相关文章:

c++ - 在运行时删除/修改静态 Qt 资源

c++ - QFile 既不读取也不打开我的文件

c++ - Qt5,文件夹的符号链接(symbolic link)

c++ - 如何在 QT 中读取 GPX 文件(xml 格式)?

c++ - QT文件打开不创建文件

mysql - Qt动态加载MySQL驱动

qt - 具有 2 种渲染模式的 QGLWidget

Qt5 & QtQuick2 - 透明主窗口

python - 信号问题 - 插槽,aboutToQuit()

c++ - 内部Klocwork的资源泄漏