c++qtqproperty

QT Q_PROPERTY error: linker command failed with exit code 1 (use -v to see invocation)


I tried to set up a property so that the value of a variable is change a function will be called:

The DataExchange class:

#ifndef DATAEXCHANGE_H
#define DATAEXCHANGE_H

#include <QObject>
#include <QDebug>

class DataExchange : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool serialOn READ get_serialOn WRITE set_serialOn NOTIFY serialOnChanged)
public:
    DataExchange(QObject *parent = 0);
    ~DataExchange();

    bool get_serialOn() const
    {
        return _serialOn;
    }

    void set_serialOn(bool value)
    {
        if (value != _serialOn)
        {
            _serialOn = value;
            emit serialOnChanged(_serialOn);
        }
    }


signals:
    void serialOnChanged(bool);
private:
    bool _serialOn;

};

#endif // DATAEXCHANGE_H

DataExchange.cpp

DataExchange::DataExchange(QObject *parent) :
    QObject(parent)
{}
DataExchange::~DataExchange() { }

MainFrame:

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    ...
    DataExchange *deHandle;
};

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    removeToolBar(ui->mainToolBar);
    deHandle = new DataExchange;
}

But it gives the error:

error: linker command failed with exit code 1 (use -v to see invocation)

Where does this error come from and how to solve it?


Solution

  • I have uploaded the code that is similar to yours but I have no problems: github.com/eyllanesc/stackoverflow/tree/master/Test – eyllanesc

    This one is a good example. But after changes were made, need to: clean project -> run qmake -> ...

    Then it will finally work.

    Previously I only cleaned project and rebuilt project, which somehow didn't solve problem.