N
N
Nicky232020-05-16 18:40:54
Qt
Nicky23, 2020-05-16 18:40:54

How to get rid of undefined reference to error?

Good afternoon! I have this problem:
In the first project I used signals and slots:
.h file:

// Код...
Q_OBJECT
signals:
    signal1();
    signal2();
// Код...

In the .cpp file, I just take and call them at the right time. And everything works well.

But in the second project, I have two classes, one parent, without an interface, and the other child, with an interface. Those. in the parent class, I do not use Q_OBJECT, and even if I write it, there will be an error ... I create several signals in the parent class, then I create a child class from it:
class Parent
{
signals:
    signal1();
    signal2();
protected:
    // Методы, в которых я вызываю сигналы

In child class:
class Child : public Parent
{
Q_OBJECT
// Код...
}


When I run it I get an error:
undefined reference to 'Parent::signal1()'
undefined reference to 'Parent::signal2()'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-05-16
@Nicky23

In order for the signal slots to work, it is just necessary that the class be a descendant of QObject or a descendant of any successor of QObject. You also need the Q_OBJECT macro where signals or slots sections are used. You also missed the type in the signal names.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question