Results 1 to 6 of 6

Thread: How to integrate Log4Qt into a project?

  1. #1
    Join Date
    May 2009
    Location
    Germany
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to integrate Log4Qt into a project?

    Hi, i currently try to integrate Log4Qt into my project but nothing seems to work. My setup as following:

    /path-to-programming-stuff/librarys/log4qt/ <- Clone of the git repository of log4qt
    /path-to-programming-stuff/librarys/log4qt-install/ <- Compiled log4qt libraries after installing
    /path-to-programming-stuff/qt/TestProject/ <- Project which should use log4qt

    The test project is a simple out of the box qt project with a mainwindow. To be exact it's the thing you get if you create a new qt widget project.

    My first try was to compile log4qt according to the readme as a shared library with mingw of the qt installation. Make and make install worked perfectly.
    My pro file:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = LogTest
    4. TEMPLATE = app
    5.  
    6. INCLUDEPATH += /path-to-programming-stuff/librarys/Log4Qt-install/include
    7.  
    8. LIBS += -L /path-to-programming-stuff/librarys/Log4Qt-install/lib libLog4Qt
    9.  
    10. SOURCES += main.cpp \
    11. MainWindow.cpp
    12.  
    13. HEADERS += MainWindow.h
    14.  
    15. FORMS += MainWindow.ui
    To copy to clipboard, switch view to plain text mode 

    And the MainWindow.cpp:
    Qt Code:
    1. #include <log4qt/ConsoleAppender>
    2. #include <log4qt/LogManager>
    3. #include <log4qt/Logger>
    4. #include <log4qt/TTCCLayout>
    5. #include <QDebug>
    6.  
    7. #include "MainWindow.h"
    8. #include "ui_MainWindow.h"
    9.  
    10. MainWindow::MainWindow(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::MainWindow)
    13. {
    14. ui->setupUi(this);
    15.  
    16. qDebug() << "Help";
    17.  
    18. Log4Qt::LogManager::rootLogger();
    19. Log4Qt::TTCCLayout *p_layout = new Log4Qt::TTCCLayout();
    20.  
    21. p_layout->setName(QLatin1String("My Layout"));
    22. p_layout->activateOptions();
    23.  
    24. // Create an appender
    25. Log4Qt::ConsoleAppender *p_appender = new Log4Qt::ConsoleAppender(p_layout, Log4Qt::ConsoleAppender::STDOUT_TARGET);
    26. p_appender->setName(QLatin1String("My Appender"));
    27. p_appender->activateOptions();
    28.  
    29. // Set appender on root logger
    30. Log4Qt::Logger::rootLogger()->addAppender(p_appender);
    31.  
    32. Log4Qt::Logger::logger(QLatin1String("My Logger"))->info("Hello World!");
    33. }
    34.  
    35. MainWindow::~MainWindow()
    36. {
    37. delete ui;
    38. }
    To copy to clipboard, switch view to plain text mode 

    The directory "/path-to-programming-stuff/librarys/log4qt-install/bin/" with the compiled library is added to the project properties (PATH). This compiles but crashes at runtime with "The program has unexpectedly finished." No error message.

    Second idea was to use include() and the Log4Qt.pri file:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = LogTest
    4. TEMPLATE = app
    5.  
    6. include(/path-to-programming-stuff/librarys/log4qt/src/Log4Qt.pri)
    7.  
    8. SOURCES += main.cpp \
    9. MainWindow.cpp
    10.  
    11. HEADERS += MainWindow.h
    12.  
    13. FORMS += MainWindow.ui
    To copy to clipboard, switch view to plain text mode 

    This doesn't compile and gives following error:
    Qt Code:
    1. In file included from ..\..\librarys\log4qt\src\appenderskeleton.cpp:38:
    2. ..\..\librarys\log4qt\src\/spi/filter.h:33:31: error: helpers/logobject.h: No such file or directory
    3. ..\..\librarys\log4qt\src\/spi/filter.h:35:34: error: helpers/logobjectptr.h: No such file or directory
    4. mingw32-make.exe[1]: *** [release/appenderskeleton.o] Error 1
    5. mingw32-make.exe: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    Also the includes in MainWindow.cpp don't work anymore. No log4qt class can be found with qt creator.

    Does anyone has an idea?
    Last edited by kei; 7th August 2012 at 17:50.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to integrate Log4Qt into a project?

    The directory "/path-to-programming-stuff/librarys/log4qt-install/bin/" with the compiled library is added to the project properties (PATH). This compiles but crashes at runtime with "The program has unexpectedly finished." No error message.
    Ever thought about running your program in the debugger and actually seeing what's going wrong by looking at the call stack when it crashes?

    It simply astounds me that people compile their programs in release mode, run it, it crashes, and then are amazed that they get a message box that tells them "The program has unexpectedly finished" with no other information. That's what compiling in debug mode and running under a debugger is for. It tells you why the program unexpectedly finished, and the answer is usually that you made a programming error that caused the crash, and the debugger usually points you to exactly the line in your code that is responsible for it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2009
    Location
    Germany
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to integrate Log4Qt into a project?

    Sorry forgot to mention but yeah i did that, too. It crashes with "Executable failed: During startup program exited with code 0x0000139". Some sources say this means there is a dll missing. But even if i copy all dlls in the same folder as the executable it crashes with "The application was unable to start correctly (0xc0000005)".

  4. #4
    Join Date
    Aug 2012
    Posts
    8
    Thanks
    1

    Default Re: How to integrate Log4Qt into a project?

    I would go for method two, http://log4qt.sourceforge.net/ has an easy guide, but it seems like you did that. Make sure the paths exists, and the case is right(my log4qt.pri is all lowercase). Make sure that your slashes are the correct way, it's weird how your error:

    Qt Code:
    1. ..\..\librarys\log4qt\src\/spi/filter.h
    To copy to clipboard, switch view to plain text mode 

    has \ during your path and / during the path to the library.

    My sample include is

    Qt Code:
    1. include(./Utilities/log4qt/src/log4qt/log4qt.pri)
    To copy to clipboard, switch view to plain text mode 

    It's probably a typo, so go over everything carefully.

  5. #5
    Join Date
    May 2009
    Location
    Germany
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to integrate Log4Qt into a project?

    After playing a bit i found that it works with the original version (from sourceforge) but not with the newer fork (from gitorious). Currently i'm using the original version which works fine. I also got the fork working but not in a nice manner (building it with the given .pro-file and including the source folder which converts to ugly includes). The fork gives an installation description which consists of compiling with cmake and installing with mingw (which copies necessary files into the qt sdk folder and registers it). After this you can include everything in a nice manner (e.g. #include <Log4Qt/ConsoleAppender>) and you only need to add "CONFIG+=Log4Qt" in the .pro-file. Well in theory. But when compiling it fails and cannot find the log4qt classes.

    So far thx for the help.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to integrate Log4Qt into a project?

    "The application was unable to start correctly (0xc0000005)"
    If this is a Windows platform, this means you have a segmentation fault due to either trying to use a NULL pointer or a pointer that contains garbage because it is uninitialized. Put a breakpoint in main() and start stepping through until you hit the crash, and there's your bad pointer.

    And in Visual Studio at least, you generally cannot mix-and-match debug and release mode DLLs and executables. If you're putting release mode DLLs into a folder and then trying to run debug-mode apps, you could be running into trouble because the memory layout of release and debug mode objects is different.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Using Log4QT
    By gpuntoni in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2016, 03:14
  2. How to Integrate Qt Designer to a Qt project?
    By adamsakli in forum Qt Tools
    Replies: 1
    Last Post: 12th March 2010, 13:52
  3. Replies: 0
    Last Post: 30th July 2009, 21:56

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.