1

i can't compile this QT program because I get this message about "multiple definition of `Dialog::status(QString const&)'"

There is some code: 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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.