view raw
no name no name - 7 months ago 53
C++ Question

How to write to text file on windows C dirve using Qt

I want to write a file on C drive on windows using Qt c++
what I try

QFile file("C:/key.txt");
if (!file.exists())
{ | QIODevice::Text);

but nothing was written on C i think i should give it admin permissions so it can write to C drive but i search and found QFile::setpermissions
but it did't solve the problem too

so any idea to solve my problem please
Thanks in Avdance


You need to run your application with administrator privileges to write to C:. It requires to by pass UAC. To do that, embed the manifest:

QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"

or you can adjust your application manifest:

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>