Results 1 to 2 of 2

Thread: Log file Location for Windows 7 Application

  1. #1
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Log file Location for Windows 7 Application

    I'm writing a Qt Application for Windows 7 and I'm currently adding a relatively crude log-to-file mechanism.

    • I'm using a QTextStream linked to a QFile (QIODevice::WriteOnly | QIODevice::Text) to write data to file
    • I'm installing a QMsgHandler using qInstallMsgHandler which appends a timestamp to the message and then writes it to file using the QTextStream
    • I'm planning on having the logging running in a separate thread, but I'll get to that later


    For the moment, I'm stuck on where I should actually create the log file under Windows 7. I'm developing in VS 2008 and using Windows Installer to create installation packages. My Qt application installs under C:\Program Files\..., which works fine for running the application without creating the log file. But Windows is not allowing my application me to create the log file in C:\Program Files, unless I run the application as Administrator.

    Is there standard pattern for this? Does Windows prefer the log files be written somewhere else (an equivalent of Linux's /var/log)?

    Any help appreciated.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Log file Location for Windows 7 Application

    Applications should not write to the "Program Files" location at run time: this is blocked by Windows 7. You have a couple of options depending on what the intended use of the file is, its permanence, and how easy you want it to be found by your users. Use QDesktopServices to locate the user's documents directory or the application data/cache directory. You could also write to the system temporary directory (QTemporaryFile).

    MSDN has a whole bunch of guidance on this if you want to go Windows-specific.

  3. The following user says thank you to ChrisW67 for this useful post:

    stefanadelbert (22nd July 2010)

Similar Threads

  1. Replies: 3
    Last Post: 12th July 2010, 06:25
  2. Replies: 4
    Last Post: 11th March 2010, 13:52
  3. Replies: 4
    Last Post: 16th February 2010, 17:42
  4. Replies: 2
    Last Post: 2nd April 2008, 17:28
  5. Replies: 3
    Last Post: 25th May 2007, 07:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.