no name no name - 1 year ago 139
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

Answer Source

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"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download