[SOLVED] Problem writing to a file when starting app from command line

  • I have a wierd problem where none on my log entries are written to the log file when I start my application from command line (simply calling the .exe). Demonstration:

    QFile *f = new QFile(global_logs_dir + "common_logs.txt");
    QByteArray ba(QString("Test log entry").toLatin1());

    When I run the .exe by double clicking the .exe, all works fine. The show messages say "logs/common_logs.txt" and "14" as they should. When I call the .exe from command line, I get the identical show messages, but nohing is written to the file!

    I'm testing on Windows 7 platform. I've tried to set the rights to the folder, by setting All privalegies to Everyone. I've also tried to open the CMD as admin etc. What causes this?!

  • Lifetime Qt Champion


    Where are you looking for this file ? Are you sure it's the right folder ?
    Since you are using a relative path to your log file you might not be writing it where you think it should go

  • Ah, I used the f->fileName() to check this, but somehow I did not pay any attention the fact that I wasn't relative path (only showed logs/common_logs.txt).

    I now updated the global_logs_dir variable with applicationDirPath() from the QApplication object, and it works. Thank you!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.