Seite 1 von 1

Problem mit Windows Registry

Verfasst: 27. Juni 2007 16:36
von qtp
Hy,

ich habe ein Programm, das Infos aus einer Datei einliest.
Das klappt alles einwandfrei, aber wenn ich das Programm in den run-Schlüssel der Registry eintrage, damit das Programm beim Systemstart startet, findet er die Datei nicht mehr!!!
Zur Information: Den Schlüssel hab ich per Hand angelegt und die Datei befindet sich im selben Verzeichnis wie das Programm. Ich habs auch schon mit QDir::currentPath() versucht, aber jedesmal sagt er, dass die Datei nicht da ist??
WARUUUMM??

Hab hier mal ein Testprog:

Code: Alles auswählen

if (!checkAllSekProgs())
    {
        QMessageBox::warning(this,"Info","Nicht gefunden!",QMessageBox::Ok,0,0);
        exit(0);
    }
    else
    {
        QMessageBox::warning(this,"Info","Gefunden!",QMessageBox::Ok,0,0);
        exit(0);
    }
}
bool Form::checkAllSekProgs()
{
    QString s=QDir::currentPath();
    int pos=0;
    while (s.indexOf("/")!=-1)
    {
        pos=s.indexOf("/",pos+1);
        s=s.replace(pos,1,"\\");
    }
    //if (!QFile::exists(QDir::currentPath()+"/cl.exe"))
    if (!QFile::exists(s+"\\cl.exe"))
            return false;

    return true;
}
Nichts funktioniert, jedesmal gibt er "Nicht gefunden" aus!

Helft mir! :cry:

Verfasst: 27. Juni 2007 18:48
von RD1978
Hallo,

vesuch´s mal mit QCoreApplication::applicationDirPath()
QString QCoreApplication::applicationDirPath() [static]

Returns the directory that contains the application executable.
MfG RD1978

Verfasst: 28. Juni 2007 11:26
von qtp
Hab es anders gelöst:

Code: Alles auswählen

QString path=app.applicationFilePath();
int index=path.lastIndexOf("/");
QString pfad=path.remove(index+1,path.length());
Das steht in der main.cpp und die Variable pfad wird dem Konstruktor als Argument übergeben, sodass man dann damit arbeiten kann. Aber trotzdem danke für deine Idee!

MfG qtp

Verfasst: 28. Juni 2007 11:43
von RD1978
Hallo,

Wie wär´ s denn mit dem globalen Pointer qApp?

Code: Alles auswählen

qApp->applicationFilePath();
Das kannst Du von überall aus aufrufen, dann sparst Du Dir das mit den Parametern.

MfG RD1978

Verfasst: 28. Juni 2007 13:03
von macman
qtp hat geschrieben:

Code: Alles auswählen

QString path=app.applicationFilePath();
int index=path.lastIndexOf("/");
QString pfad=path.remove(index+1,path.length());
Doku nicht gelesen? Es gibt QApplication::applicationDirPath(). Und das funktioniert auch mit qApp.