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);
// 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?
Thanks for the help,
Jec
Adding a manifest file is the route I choose to fix this problem.
Thanks for all of the help.
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.
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.)
For more details, see New UAC Technologies for Windows Vista (scroll down and look for Virtualization.)