这让我疯了......它早先工作了,但不行不通。我已经定义了Q_SLOTS和Q_SIGNALS,我试图连接它们。它工作到一定程度......然后突然间一切都停止了工作,现在我得到了错误。我的代码如下:
ControllerLogic.h
#ifndef CONTROLLERLOGIC_H
#define CONTROLLERLOGIC_H
#include "initdataaccess.h"
#include "mainframe.h"
#include <QtGui>
#include "initializationdatastructure.h"
/** This is a controller class; refering to the model-view-controller
* architecture.
*/
class ControllerLogic : public QObject
{
Q_OBJECT
public:
ControllerLogic(InitDataAccess *initDataAccess, MainFrame *mainFrame);
Q_SIGNALS:
void Signal();
private:
void setMainFrame(MainFrame mainFrame);
public Q_SLOTS:
void receive();
};
#endif // CONTROLLERLOGIC_H
ControllerLogic.cpp
#include "controllerlogic.h"
#include "licensedataaccess.h"
#include <qobjectdefs.h>
// obsolete...may be used later
ControllerLogic::ControllerLogic(InitDataAccess *initDataAccess, MainFrame *mainFrame)
{
connect(this, SIGNAL(signal()), mainFrame, SLOT(PrintTestSlot()));
}
void ControllerLogic::receive(){
qDebug()<<"RECEIVE";
}
void ControllerLogic::Signal(){
qDebug()<<"SIGNAL";
}
错误
moc_controllerlogic.obj:-1: error: LNK2005: "protected: void __thiscall ControllerLogic::Signal(void)" (?Signal@ControllerLogic@@IAEXXZ) already defined in controllerlogic.obj
release\TSLSuite.exe:-1: error: LNK1169: one or more multiply defined symbols found
我还尝试按如下方式定义信号:
public:
Q_SIGNAL void Signal();
但我得到同样的错误。
发生了什么事? 请帮助!
谢谢!
答案 0 :(得分:7)
问题在于您正在尝试定义名为Signal()
Qt为您生成“信号”函数的主体,如果您尝试创建自己的定义,您将得到您正在描述的错误。
(作为旁注,您的连接语句似乎已损坏s/signal/Signal/
)