gpt4 book ai didi

Qt 不能创建/写入 C :\

转载 作者:行者123 更新时间:2023-12-04 13:23:13 25 4
gpt4 key购买 nike

我正在编写一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com