Qt cannot help but create / write in C: \

I am writing a Qt program (first 4.7 for Windows 7), which requires writing to the installed directory (C: \ Program Files ...). When you try to write to a place that will be "protected" (program files, C: \ etc), files are not created. However, QFile does not give me any error code (error () returns 0, which means that it worked fine).

Here is a piece of code that I am using that does not work. I close its file 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 that I decided to solve this problem.

Thanks for the help.

+5
source share
3

, VirtualStore ? → Microsoft → Windows → UacFileVirtualization → Operational. 5000, FileCreateVirtualExclude.

, %USERPROFILE%\AppData\Local\VirtualStore. , , (.. ).

. UAC Windows Vista ( .)

+7

Windows Vista + (, " " ). WinAPI.

+2

QFile may indicate an error code, but you could not verify it.

You need to do something more:

if (!debugFile.open(QFile::WriteOnly)) {
    qWarning() << "Failed to open" << debugFile.fileName() << "for write:" << debugFile.errorString();
}

You checked the return value QFile::error, but only before the call open- you need to check after trying to open.

+2
source

All Articles