当我向我的脚本添加插槽时,它将不再构建。
inkpuppet.obj:-1: error: LNK2005: "private: void __cdecl InkPuppet::on_aboutButton_clicked(void)" (?on_aboutButton_clicked@InkPuppet@@AEAAXXZ) already defined in main.obj
和
debug\InkPuppet.exe:-1: error: LNK1169: one or more multiply defined symbols found
以下是代码:
inkpuppet.h - 注释void on_aboutButton_clicked();
,最后的功能将使其运行。
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QtCore>
namespace Ui {
class InkPuppet;
}
class InkPuppet : public QWidget
{
Q_OBJECT
public:
explicit InkPuppet(QWidget *parent = 0);
~InkPuppet();
private:
Ui::InkPuppet *ui;
private slots:
void on_aboutButton_clicked();
};
#endif // WIDGET_H
void InkPuppet::on_aboutButton_clicked()
{
}
inkpuppet.cpp
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
InkPuppet::InkPuppet(QWidget *parent) :
QWidget(parent),
ui(new Ui::InkPuppet)
{
ui->setupUi(this);
//connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), ui->timeSlider, SLOT(setRange(int,int)));
}
InkPuppet::~InkPuppet()
{
delete ui;
}
的main.cpp
#include "inkpuppet.h"
#include "aboutdialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
InkPuppet w;
w.show();
return a.exec();
}
aboutdialog.h
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QDialog>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
private:
Ui::AboutDialog *ui;
};
#endif // ABOUTDIALOG_H
aboutdialog.cpp
#include "aboutdialog.h"
#include "ui_aboutdialog.h"
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
ui->setupUi(this);
}
AboutDialog::~AboutDialog()
{
delete ui;
}
答案 0 :(得分:2)
您在inkpuppet.h中定义了void InkPuppet::on_aboutButton_clicked()
。然后将它包含在inkpuppet.cpp和main.cpp中 - &gt;找到一个或多个多重定义的符号。
放
void InkPuppet::on_aboutButton_clicked()
{
}
在你的inkpuppet.cpp文件中。
答案 1 :(得分:1)
如果您粘贴的第一个文件是一个整体,则包含警卫会出现问题。 后卫的定义是。
#endif // WIDGET_H
void InkPuppet::on_aboutButton_clicked()
{
}
您的定义就在#endif
之后,这意味着只要在同一个翻译单元中,标题包含两次,您就会收到此错误。这会发生在您的代码中,因为inkpuppet.h
和main.cpp
中都包含inkpuppet.cpp
您应该将on_aboutButton_clicked()
的实施代码放在inkpuppet.cpp
文件中。< / p>