[英]QT - multiple definitions
i can't compile this QT program because I get this message about "multiple definition of `Dialog::status(QString const&)'" 我无法编译这个QT程序因为我得到关于“Dialog :: status(QString const&)”的多重定义的消息
There is some code: Dialog hader: 有一些代码:Dialog hader:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
//class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
signals:
void status(const QString &str);
private slots:
void on();
private:
QLabel *label;
QLineEdit *LineEdit;
QPushButton *button;
};
#endif // DIALOG_H
and implementation file: 和实施文件:
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include "dialog.h"
Dialog::Dialog(QWidget *parent) : QDialog(parent)
{
label = new QLabel("Ne label");
LineEdit = new QLineEdit();
button = new QPushButton("Push me");
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(label);
layout->addWidget(LineEdit);
layout->addWidget(button);
setLayout(layout);
setWindowTitle("Dialog name");
connect(button, SIGNAL(clicked()), this, SLOT(on()));
}
void Dialog::on()
{
label->setStyleSheet("QLabel { background-color : black; color : white; }");
}
void Dialog::status(const QString &str)
{
}
project file looks fine: 项目文件看起来很好:
QT += gui declarative
SOURCES += \
main.cpp \
dialog.cpp
HEADERS += \
dialog.h
Thanks for your help. 谢谢你的帮助。
You declare the status function as a signal and then implement a body for it. 您将状态函数声明为信号,然后为其实现一个主体。 Signals are just that, a signal and do not have an implementation.
信号只是一个信号而没有实现。
Depending upon your intent, you need to either remove the body implementation for the status function, or move the declaration to being a slot, not a signal. 根据您的意图,您需要删除状态函数的body实现,或将声明移动为插槽而不是信号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.