当我在脚本中添加插槽时,它将不再构建。

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


关于对话框

#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


关于dialog.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;
}

最佳答案

您可以在inkpuppet.h中定义void InkPuppet::on_aboutButton_clicked()。然后将其包含在inkpuppet.cpp和main.cpp中->找到一个或多个乘法定义的符号。



void InkPuppet::on_aboutButton_clicked()
{

}


在您的inkpuppet.cpp文件中。

09-10 17:03