当有信息消息或发生错误时,我有一个应该发出信号的类applicationManager
,而我想通过 QXmppLogger 类对象记录使用它的消息。有一个 QXmppLoggable 类,它具有类似的方法info()
并warning()
发出logmessage()
内部 QXmppLogger 的信号。因此,为了发出信号,我继承了 QXmppLogable 类,该类继承了 QObject 本身,因此能够使用info()
并通过 info() 和 warning() 方法warning()
将发出的 SIGNAL( ) 连接到QXmppLogger 对象的 SLOT()。这是代码片段:logmessage()
log()
标题"imApplicationManager.h"
class applicationManagement: public QXmppLoggable
{
//Q_OBJECT
public:
bool createDataBaseConnection();
applicationManagement();
~applicationManagement();
void setLogger(QXmppLogger *logger);
private:
QXmppLogger *logger;
};
和相关的"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;
}
在里面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();
}
编译通知没有错误,但是当启动时有一个 Sigmentation 错误。我该如何解决?