Results 1 to 5 of 5

Thread: Using qDebug to write to an external file

  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Using qDebug to write to an external file

    I would like to use qDebug in my application, and have it write to an external Log file. This way I can check for messages when the application is running in 'release' mode.

    The version of Qt I am using is 3.3.5 (I know it is outdated et al, but my project is on it). The qDebug notes in QtAssistant doesn't provide information on writing to an external file. I would like to know if this is possible, and how to do it.

    Thanks in advance.
    Last edited by qtUser500; 16th November 2009 at 16:17.

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using qDebug to write to an external file

    As written in QtAssistant, qDebug() calls the message handler and if no message handler has been installed, the message is simply printed on stderr. Thus you can either redirect stderr to a file while executing your application or install your custom handler.

    Can't you just use QFile class?
    Last edited by calhal; 16th November 2009 at 16:04. Reason: updated contents
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Using qDebug to write to an external file

    Thanks calhal for your input.

    Yes I can use QFile, but was wondering whether there was an inbuilt functionality in qDebug where I can both write to file as well as send it to output. So that it can be used both for release and debug modes of the application.

    Well it looks like I will just need to stick to QFile instead. Thanks anyways!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using qDebug to write to an external file

    Make a custom message handler as suggested by calhal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Using qDebug to write to an external file

    Thank you both for the suggestions.
    Appreciate it.

Similar Threads

  1. External Javascript file not loading initially
    By bkudrle in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2009, 17:05
  2. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  3. Replies: 16
    Last Post: 23rd May 2008, 10:12
  4. About File write operation
    By raghvendramisra in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2008, 11:41
  5. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48

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.