Results 1 to 13 of 13

Thread: Generating Log files

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Generating Log files

    Hi

    I want to generate a log file for my application. Does Qt have any inbuilt function for that??

    I am using qDebug to return some information during the execution of the process.

    I want to put all my qDebug and qWarnings into a log file along with the time of generation of the text.

    I can stream the qDebug into a file,before i do that, i want to know if there are any inbuilt function.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    have a look at qInstallMsgHandler, you can install your message handler which will save qDebug info into file. also read this thread.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Generating Log files

    thanks mate. the thread and the qInstallMsgHandler helped.

    But the log file keeps on writing in the same line. it doesnt go to the next line.
    there is a endl in the code.

    any ideas as to how to fix this?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    that code works fine for me.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Generating Log files

    I am using this code
    Qt Code:
    1. void myMessageHandler(QtMsgType type, const char *msg)
    2. {
    3. QString txt;
    4. QDateTime date;
    5.  
    6. txt = msg;
    7. txt.prepend(" - ");
    8. txt.prepend(date.currentDateTime().toString());
    9.  
    10. QFile outFile("log.txt");
    11. outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    12. QTextStream ts(&outFile);
    13. ts << txt <<endl<<flush;
    14.  
    15.  
    16. }
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. qInstallMsgHandler(myMessageHandler);
    21. QApplication a(argc, argv);
    22. MainWindow w;
    23. return a.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    I am able to get all the data in 1 line
    Tue Jul 14 10:15:54 2009 - i am in debug
    Tue Jul 14 10:16:06 2009 - i am in debug
    One more question, will qDebug work only if the app is built in debug mode??

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    try to pass "\n" instead of endl.. QTextStream takes care of unix and windows line deliminaters.
    qDebug will work in debug mode only i think.

  7. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Generating Log files

    i am not able to see the text in the new line only if i open the file in notepad.

    If I open the same file in wordpad its all written in different lines.

    weird

    thanks for the info.

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    I've just ran code again and got the following result
    Tue Jul 14 16:19:47 2009 - "00in.png"
    Tue Jul 14 16:19:47 2009 - "00out.png"
    Tue Jul 14 16:19:47 2009 - "01in.png"
    ...
    i.e. works fine, btw in release mode I had the same result.
    PS. what platform do you use? what is Qt's version? I've tested on windows.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Generating Log files

    I am using Qt 2.1 and it is working even in release mode.

    I am able to get each statement in a new line if I open the file in wordpad.

    thanks for the help

  10. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    HOLY COW!! ... Qt 2.1...!!!!!!

  11. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    Quote Originally Posted by srohit24 View Post
    I am using Qt 2.1 and it is working even in release mode.

    I am able to get each statement in a new line if I open the file in wordpad.

    thanks for the help
    wow, I don't even know what to say
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #12
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Generating Log files

    I have installed this

    qt-sdk-win-opensource-2009.02.1.exe

  13. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generating Log files

    so, this is not Qt 2.1, this is Qt 4.5.x.
    is the problem solved?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Generating .pro files from vcproj file or CMake file
    By ramazangirgin in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2009, 10:37
  2. visual studio project files - adding extra files
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 22:05
  3. compiling problem / Qt DLL files
    By ht1 in forum Newbie
    Replies: 1
    Last Post: 5th January 2008, 18:58
  4. Replies: 5
    Last Post: 22nd September 2006, 09:04
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 11:28

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.