QFile path changing from build version to deploy version

269 views Asked by At

I have a program that saves data inside it's own folder. This is how I save the data:

QString path = "./config/Values/"+Name+"/";
QDir *myDir = new QDir();
myDir->mkpath(path);
path += Name+"_";
path += Date+".txt";
QFile File(path);
QTextStream Out(&File);
Out.setCodec("UTF-8");
if(!File.open(QFile::WriteOnly | QFile::Text))
   return;
out << data;
File.close();

Every time I run the program through QT, the saved data goes to the path: C:\Andre\Qt files\build-Pesquisa-Desktop_Qt_5_7_0_MinGW_32bit-Release\release\config\Values. I will send the full path for clarity sake.

However, I made an installer for that program. The program is installed in C:\Program Files (x86)\SOCC_Pesquisa. So the new path should be: C:\Program Files (x86)\SOCC_Pesquisa\config\Values right?

Although, when I run the program and check where the data was saved, I get this path: C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values. Why does it change suddently to such a different folder?

EDIT: Via making a few tests I found out the problem is not in the installer, but in the place where it is installed. For some reason when I pass my program to C:\Program Files (x86), the data is always saved in C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values. is it because of the user? or maybe admin rights?

1

There are 1 answers

6
Luca Angioloni On BEST ANSWER

Due to security features introduced with Windows Vista (UAC) any non-Administrator program that tries to write to protected locations such as "Program Files" will get their writes caught and redirected to an alternative "user friendly" location.

In you case C:\Users\SOCC\AppData\Local\VirtualStore\Program Files (x86)\SOCC_Pesquisa\config\Values

You can find out more about UAC here on Wikipedia

So you can move in these directions:

  1. Run program as administrator each time.
  2. Change directory's security settings: going properties, select the Security tab and then advanced.
  3. Request elevation for your app as you can find on Wikipedia link.
  4. Change the savings location to a more secure and usual, like documents or whatever you want not conflicting with UAC