QT slots and inheritance: why is my program trying to connect to the parent rather than the child class?

In a QT program, I have a QWidget class, which is a superclass of another class declared like this:

class Renderer : public QGLWidget { Q_OBJECT .... } class A : public Renderer { .... } 

Now I have a slot for class A, which is missing from Renderer, but when I try to run the program, it cannot connect to class A:

 Object::connect: <sender name: 'push_button'> Object::connect: <receiver name: 'A'> Object::connect: No such slot Renderer::loadDialog() in <file path> 

Why is he trying to connect to Renderer and not A? Should I have a slot in Renderer with the same name?

thanks

edit:

here is the slot declaration in A:

 public slots: void loadDialog(); 

and for connections I rely more on QT Creator, but here is what was in the ui_windows.h file:

 QObject::connect(pushButton, SIGNAL(clicked()), A, SLOT(loadDialog())); 

Hope that clears up a bit :)

+7
c ++ inheritance signals-slots qt4
source share
2 answers

Can you show the code in which you connect the signal and slot? It might also be helpful to see the slot declaration in class A.

EDIT:

Try adding the Q_OBJECT macro to subclass A. Another thing may be that the slot is not virtual (but according to what I read, this should not change).

This is just a hunch, the code you posted looks good to me. I do not have Qt on this computer, so I can not try: (.

+12
source share

The problem is that class A did not have a Q_OBJECT declaration, so the signals and slots do not work with it. See http://doc.qt.io/qt-5/signalsandslots.html

+3
source share

All Articles