Qt无法创建/写入C:\ [英] Qt cannot cannot create/write to C:\
问题描述
我正在编写一个Qt程序(最初是Windows 7的4.7),需要写入已安装的目录(C:\ Program Files ...).当我尝试写入将被保护"的位置(程序文件,C:\等)时,没有文件正在创建.但是,QFile没有给我任何错误代码(error()返回0,这意味着它工作正常).
I am writing a Qt program (4.7 for windows 7 initially) that requires writing to the installed directory (C:\Program Files...). No files are being created when I try to write to a location that would be "protected" (program files, C:\ etc). However, QFile is not giving me any error code (error() is returning 0 which means it worked fine).
这是我使用的代码片段,无法正常工作.我即将在程序中关闭文件.
Here is a code snippit that I am using that is not working. I am closing the file its just much later in the program.
QApplication a(argc,argv);
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");
有人对如何解决此问题有任何提示吗?
Does anyone have any tips on how to solve this problem?
感谢您的帮助,
杰克
添加清单文件是我选择解决此问题的途径.
Adding a manifest file is the route I choose to fix this problem.
感谢所有帮助.
推荐答案
您是否检查了是否未在VirtualStore中为该用户创建文件?在应用程序和服务日志"->"Microsoft"->"Windows"->"UacFileVirtualization"->可操作"下检查事件查看器".如果看到事件ID为5000的条目,则发生了FileCreateVirtualExclude事件.
Have you checked whether the file isn't created in the VirtualStore for that user? Check the Event Viewer under Applications and Services Logs -> Microsoft -> Windows -> UacFileVirtualization -> Operational. If you see entries with event ID 5000, a FileCreateVirtualExclude event has occurred.
检查是否未在%USERPROFILE%\AppData\Local\VirtualStore
下创建文件.如果确实如此,则可能需要嵌入清单以请求所需的特权(即,关闭虚拟化.)
Check if the file didn't get created under %USERPROFILE%\AppData\Local\VirtualStore
. If it did, you might need to embed a manifest requesting the required privileges (i.e., turning virtualization off.)
有关更多详细信息,请参见适用于Windows Vista的新UAC技术(向下滚动并查找虚拟化.)
For more details, see New UAC Technologies for Windows Vista (scroll down and look for Virtualization.)
这篇关于Qt无法创建/写入C:\的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!