Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt slots and inheritance: why is my program trying to connect to the parent instead of the child class?

In a Qt program, I have a QWidget class that is the superclass of another class declared so:

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

class A : public Renderer
{ .... }

Now I have a slot for class A that is not present in Renderer, but when I try to run the program, it fails to make connections 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 it trying to connect to Renderer and not A? Am I supposed to have a slot in Renderer of the same name?

Thanks

edit:

here's the declaration of the slot in A:

public slots:
    void loadDialog();

and as for the connections, I'm relying on Qt Creator mostly, but here's what was in the ui_windows.h file:

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

Hope that clears things up a bit :)

like image 795
confusedKid Avatar asked Dec 01 '10 07:12

confusedKid


1 Answers

Can you show the code where you connect the signal and slot? Maybe it would also be helpful to see the slot declaration in class A.

EDIT:

Try to add Q_OBJECT macro in subclass A. Another thing could be that the slot is not virtual (but according to what I read that shouldn't make a difference).

These are just guesses, the code you posted looks ok for me. I don't have Qt available on that computer so I can't try it out :(.

like image 131
mPopp Avatar answered Oct 06 '22 23:10

mPopp