budda
7th October 2011, 01:06
SO I wrote an application with Qt 4.6 in Windows 7, that uses a few .txt files for storing information. It runs just fine when I run it from the release folder.
However, I implemented QSettings to add the application to the registry so that it runs on system startup. It does this just fine, BUT my problem is that it then does not open and read the text files. I'm guessing because its not in the actual directory when running from the startup. At first I realized that I was using a Relative path in the same directory as the application, so I grabbed the application Dir Path through the main when I call
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString exePath = a.applicationDirPath();
MainWindow w;
w.exePath = exePath;
return a.exec();
}
exePath is a Public QString in mainwindow.h
so, when I open the file to read, I put the applicationDirPath in front of the file name and use the absolute path.
with:
QString thisDir = exePath;
thisDir += "time.txt";
QFile fileOpen(thisDir);
but this still doesn't solve the problem. And nothing is opened when it's run from startup in the registry... Does anyone know why this is happening? Are startup programs forbidden to open text files, or is it just running from some different directory still? Some tips would be great, because every time I test this, I have to restart the machine after a new change/compile/and run. And this is starting to get tedious....
However, I implemented QSettings to add the application to the registry so that it runs on system startup. It does this just fine, BUT my problem is that it then does not open and read the text files. I'm guessing because its not in the actual directory when running from the startup. At first I realized that I was using a Relative path in the same directory as the application, so I grabbed the application Dir Path through the main when I call
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString exePath = a.applicationDirPath();
MainWindow w;
w.exePath = exePath;
return a.exec();
}
exePath is a Public QString in mainwindow.h
so, when I open the file to read, I put the applicationDirPath in front of the file name and use the absolute path.
with:
QString thisDir = exePath;
thisDir += "time.txt";
QFile fileOpen(thisDir);
but this still doesn't solve the problem. And nothing is opened when it's run from startup in the registry... Does anyone know why this is happening? Are startup programs forbidden to open text files, or is it just running from some different directory still? Some tips would be great, because every time I test this, I have to restart the machine after a new change/compile/and run. And this is starting to get tedious....