Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Problem writing to a file when starting app from command line

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zerby
    wrote on last edited by
    #1

    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");
    showmessage(f->fileName());
    f->open(QFile::Append);
    QByteArray ba(QString("Test log entry").toLatin1());
    showmessage(f->write(ba));
    f->flush();
    f->close();
    @

    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?!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zerby
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved