mardi 21 avril 2015

QObject::connect failing with inheritance (no such slot, but Q_OBJECT macro defined)

My problem is best described by looking at some pseudo-code:


class A: public QWidget

    void setupUserInterface(...);
    void funcA(...);
    void funcB(...);

  // etc..

class B: public A {

  // etc..


void A::setupUserinterface(...) // uiel1, uiel2 as input
  connect(uiel1, SIGNAL(pressed()), this, SLOT(funcA()));
  connect(uiel2, SIGNAL(pressed()), this, SLOT(funcB()));

void A::funcA(...) { ... }
void A::funcB(...) { ... }

When I try to build and run, I get the following errors:

QObject::connect: No such slot B::funcA in /.../A.cpp
QObject::connect: No such slot B::funcB in /.../A.cpp

Meaning that for some reason, it is looking for B-members in A.cpp.

How can I solve this? Thanks in advance.

Update 1: Making the functions funcA and funcB virtual does not help.

Aucun commentaire:

Enregistrer un commentaire