QT 信号和槽意外错误

发布于 2024-12-21 20:00:57 字数 1684 浏览 2 评论 0原文

这让我发疯……它早些时候可以工作,但不是不起作用。我已经定义了 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";
}

ERROR

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();

但我得到了相同的错误。

到底是怎么回事? 请帮忙!

谢谢!

This is driving me insane....it was working earlier, but not it doesn't work. I have defined Q_SLOTS and Q_SIGNALS, and I was trying to connect them. It was working to an extent...and then all of a sudden everything stopped working, and now I am getting errors. My code is the following:

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";
}

ERROR

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

I also tried to define the signal as follows:

public:
Q_SIGNAL void Signal();

but I get the same error.

What is going on?
Please Help!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒眉千度 2024-12-28 20:00:57

问题是你试图定义一个名为 Signal() 的函数,

Qt 会为你生成“信号”函数的主体,如果你尝试创建自己的定义,你将得到您所描述的错误。

(顺便说一句,您的 connect 语句似乎已损坏 s/signal/Signal/

The problem is that you're trying to define a function called Signal()

Qt generates the body of the "signal" functions for you, and if you try to create your own definition, you will get the error that you're describing.

(As a side note, your connect statement appears to be broken s/signal/Signal/)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文