Tuesday, 20 August 2013

Error while inheriting QObject

Error while inheriting QObject

I've got a class applicationManager that ought to emit signal when there
is an info message or an error occurs, while I'm suppose to log that
messages consuming it by QXmppLogger class object. There is a
QXmppLoggable class that got methods like info() and warning() that emits
a signal logmessage() of internal QXmppLogger. So, in order to emit a
signal I've inherited QXmppLogable class which inherits QObject itself,
hence to be able to use info() and warning() and connected emitted
SIGNAL(logmessage()) by info() and warning() methods, to SLOT (log()) of
QXmppLogger object. Here is the code snippet:
header "imApplicationManager.h"
class applicationManagement: public QXmppLoggable
{
//Q_OBJECT
public:
bool createDataBaseConnection();
applicationManagement();
~applicationManagement();
void setLogger(QXmppLogger *logger);
private:
QXmppLogger *logger;
};
and related "imApplicationManager.cpp"
applicationManagement::applicationManagement()
{
QObject::connect(this,
SIGNAL(logMessage(QXmppLogger::MessageType,QString)),
logger, SLOT(log(QXmppLogger::MessageType,QString)));
}
applicationManagement::~applicationManagement()
{
// db..closing
}
bool applicationManagement::createDataBaseConnection(){
//...database conncetion...
if (!dataBase.open()){
warning(QString("Cannot open database
%1").arg(dataBase.lastError().text()));
qDebug()<< "Cannot open database " << dataBase.lastError();
return false;
}
info(QString("Database succeeded!"));
return true;
}
void applicationManagement::setLogger(QXmppLogger *logger)
{
if(this->logger != logger)
this->logger = logger;
}
in the main.cpp
#include "imApplicationManager"
#incLude "QXmppLogger"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
applicationManagement aa;
QXmppLogger log;
aa.setLogger(&log);
return a.exec();
}
Compilation informs of no error but when luanched there is a Sigmentation
fault. How can I fix that?

No comments:

Post a Comment