kei
7th August 2012, 17:17
Hi, i currently try to integrate Log4Qt (http://gitorious.org/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 += core gui
TARGET = LogTest
TEMPLATE = app
INCLUDEPATH += /path-to-programming-stuff/librarys/Log4Qt-install/include
LIBS += -L /path-to-programming-stuff/librarys/Log4Qt-install/lib libLog4Qt
SOURCES += main.cpp \
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
And the MainWindow.cpp:
#include <log4qt/ConsoleAppender>
#include <log4qt/LogManager>
#include <log4qt/Logger>
#include <log4qt/TTCCLayout>
#include <QDebug>
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << "Help";
Log4Qt::LogManager::rootLogger();
Log4Qt::TTCCLayout *p_layout = new Log4Qt::TTCCLayout();
p_layout->setName(QLatin1String("My Layout"));
p_layout->activateOptions();
// Create an appender
Log4Qt::ConsoleAppender *p_appender = new Log4Qt::ConsoleAppender(p_layout, Log4Qt::ConsoleAppender::STDOUT_TARGET);
p_appender->setName(QLatin1String("My Appender"));
p_appender->activateOptions();
// Set appender on root logger
Log4Qt::Logger::rootLogger()->addAppender(p_appender);
Log4Qt::Logger::logger(QLatin1String("My Logger"))->info("Hello World!");
}
MainWindow::~MainWindow()
{
delete ui;
}
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 += core gui
TARGET = LogTest
TEMPLATE = app
include(/path-to-programming-stuff/librarys/log4qt/src/Log4Qt.pri)
SOURCES += main.cpp \
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
This doesn't compile and gives following error:
In file included from ..\..\librarys\log4qt\src\appenderskeleton.cpp:38:
..\..\librarys\log4qt\src\/spi/filter.h:33:31: error: helpers/logobject.h: No such file or directory
..\..\librarys\log4qt\src\/spi/filter.h:35:34: error: helpers/logobjectptr.h: No such file or directory
mingw32-make.exe[1]: *** [release/appenderskeleton.o] Error 1
mingw32-make.exe: *** [release] Error 2
Also the includes in MainWindow.cpp don't work anymore. No log4qt class can be found with qt creator.
Does anyone has an idea?
/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 += core gui
TARGET = LogTest
TEMPLATE = app
INCLUDEPATH += /path-to-programming-stuff/librarys/Log4Qt-install/include
LIBS += -L /path-to-programming-stuff/librarys/Log4Qt-install/lib libLog4Qt
SOURCES += main.cpp \
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
And the MainWindow.cpp:
#include <log4qt/ConsoleAppender>
#include <log4qt/LogManager>
#include <log4qt/Logger>
#include <log4qt/TTCCLayout>
#include <QDebug>
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug() << "Help";
Log4Qt::LogManager::rootLogger();
Log4Qt::TTCCLayout *p_layout = new Log4Qt::TTCCLayout();
p_layout->setName(QLatin1String("My Layout"));
p_layout->activateOptions();
// Create an appender
Log4Qt::ConsoleAppender *p_appender = new Log4Qt::ConsoleAppender(p_layout, Log4Qt::ConsoleAppender::STDOUT_TARGET);
p_appender->setName(QLatin1String("My Appender"));
p_appender->activateOptions();
// Set appender on root logger
Log4Qt::Logger::rootLogger()->addAppender(p_appender);
Log4Qt::Logger::logger(QLatin1String("My Logger"))->info("Hello World!");
}
MainWindow::~MainWindow()
{
delete ui;
}
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 += core gui
TARGET = LogTest
TEMPLATE = app
include(/path-to-programming-stuff/librarys/log4qt/src/Log4Qt.pri)
SOURCES += main.cpp \
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
This doesn't compile and gives following error:
In file included from ..\..\librarys\log4qt\src\appenderskeleton.cpp:38:
..\..\librarys\log4qt\src\/spi/filter.h:33:31: error: helpers/logobject.h: No such file or directory
..\..\librarys\log4qt\src\/spi/filter.h:35:34: error: helpers/logobjectptr.h: No such file or directory
mingw32-make.exe[1]: *** [release/appenderskeleton.o] Error 1
mingw32-make.exe: *** [release] Error 2
Also the includes in MainWindow.cpp don't work anymore. No log4qt class can be found with qt creator.
Does anyone has an idea?