C++ Qt多重定义

Joh*_* M. 12 c++ qt multiple-definition-error

我正在尝试使用MinGW编译器在Qt中使用C++创建一个简单的GUI应用程序(到目前为止).然而,编译器,通知我有一个multiple definition of 'WiimoteScouter::WiimoteScouter(QWidget*)'line 4wiimotescouter.cpp.我正在使用检查以确保标题不会被多次包含,但显然它不起作用,我不知道为什么.

这是头文件:

#ifndef WIIMOTESCOUTER_H
#define WIIMOTESCOUTER_H

#include <QWidget>

class QLabel;
class QLineEdit;
class QTextEdit;

class WiimoteScouter : public QWidget
{
    Q_OBJECT

public:
    WiimoteScouter(QWidget *parent = 0);

private:
    QLineEdit *eventLine;
};

#endif // WIIMOTESCOUTER_H
Run Code Online (Sandbox Code Playgroud)

这是cpp文件:

#include <QtGui>
#include "wiimotescouter.h"

WiimoteScouter::WiimoteScouter(QWidget *parent) :
    QWidget(parent)
{
    QLabel *eventLabel = new QLabel(tr("Event:"));
    eventLine = new QLineEdit;

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(eventLabel, 0, 0);
    mainLayout->addWidget(eventLine, 0, 1);

    setLayout(mainLayout);
    setWindowTitle(tr("Wiimote Alliance Scouter"));
}
Run Code Online (Sandbox Code Playgroud)

最后,main.cpp:

#include <QtGui>
#include "wiimotescouter.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    WiimoteScouter wiimoteScouter;
    wiimoteScouter.show();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

jwe*_*rny 57

我已经看到过这种情况发生在源文件在项目(.pro或.pri)文件中重复之前.检查项目文件中的所有"SOURCES ="和"SOURCES + ="行,并确保cpp文件不在那里多次.