K
K
krembrule20162016-04-07 06:04:29
OOP
krembrule2016, 2016-04-07 06:04:29

Why do linker errors occur?

Good time of the day!
I am reading the book "Programming in C ++ in the Qt Creator
Environment" by E. R. Alekseev, G. G. Zlobin, D. A. Kostyuk,
O. V. Chesnokova, A. S.
Chmykhalo
*.pro file:

TEMPLATE = app
TARGET = ParentExample
QT += widgets

HEADERS += \
    parentwidget.h

SOURCES += \
    main.cpp \
    parentwidget.cpp

Content of parentwidget.cpp file:
#include "parentwidget.h"
#include <QLabel>
#include <QPushButton>

ParentWidget::ParentWidget(QWidget* parent):QWidget(parent)
{
    //используем указатели, чтобы дочерние элементы не удалились после завершения работы конструктора
    QLabel* ILabel = new QLabel(this); //this - это экземпляр класс ParentWidget, указывается родительский виджет
    (*ILabel).setGeometry(50,0,100,30);
    (*ILabel).setText("Привет, товарищ!");
    QPushButton* lPushButton = new QPushButton(this);
    (*lPushButton).setGeometry(50,50,100,30);
    (*lPushButton).setText("Жми!");
    setGeometry(x(),y(),300,150);
    setWindowTitle("Наследник Образец");


}

Content of parentwidget.h file:
#ifndef PARENTWIDGET_H
#define PARENTWIDGET_H

#include <QWidget>

class ParentWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ParentWidget(QWidget *parent = 0);

signals:

public slots:
};

#endif // PARENTWIDGET_H

As a result, when I try to build and run the project, I get errors of this kind:
parentwidget.obj:-1: ошибка: LNK2001: неразрешенный внешний символ ""public: virtual struct QMetaObject const * __cdecl ParentWidget::metaObject(void)const " ([email protected][email protected]@[email protected]@XZ)"

parentwidget.obj:-1: ошибка: LNK2001: неразрешенный внешний символ ""public: virtual void * __cdecl ParentWidget::qt_metacast(char const *)" ([email protected]@@[email protected])"

parentwidget.obj:-1: ошибка: LNK2001: неразрешенный внешний символ ""public: virtual int __cdecl ParentWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" ([email protected]@@[email protected]@@[email protected])"

debug\widgets.exe:-1: ошибка: LNK1120: неразрешенных внешних элементов: 3

There is a lot in the SERPs for this issue, but I don't have the relevant knowledge to get anything useful out of it.
Any thoughts? =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2016-04-07
@krembrule2016

Have you heard about the "->" operator in C++? Well, try to demolish the build folder.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question