PDA

View Full Version : Slot inheritance



kartun
28th February 2011, 12:25
May be it was answered already, but I can't find a proper solution.

1. I've base class. It does most of the work
2. I've child classes that do more specific tasks



class abstract_therapy : public QObject
{
Q_OBJECT
...
public:
void testFunction();
public slots:
void testSlot();
private:
QTimer* m1;
}


Child class :


class B : public abstract_therapy
{
Q_OBJECT
...
}


And implementation


void abstract_therapy::testFunction()
{
m1 = new QTimer(this);
m1->connect(m1, SIGNAL(timeout()), this, SLOT(testSlot()));
m1->setInterval(500);
m1->start();
}


In the program I've several classes inherited from abstract_therapy, B & C for example, and I don't use base class directly.



abstract_therapy* _therapy;
_therapy = new B;
...
_therapy->testFunction();
And on connect I receive this message :

No such slot B::testSlot()

What's the right way to connect ?

nish
28th February 2011, 12:55
just copy pasted your example and it works for me.

tst.h

class abstract_therapy : public QObject
{
Q_OBJECT
public:
void testFunction();
public slots:
void testSlot(){ qDebug() << "in slot"; }
private:
QTimer* m1;
};

class B : public abstract_therapy
{
Q_OBJECT
public:
void abc(){}
};

main.cpp

#include <QtCore>

#include "tst.h"

void abstract_therapy::testFunction()
{
m1 = new QTimer(this);
m1->connect(m1, SIGNAL(timeout()), this, SLOT(testSlot()));
m1->setInterval(500);
m1->start();
}

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

abstract_therapy* _therapy;
_therapy = new B;

_therapy->testFunction();

return a.exec();
}




and here is the output



Starting /home/nish/Desktop/progs/tst/tst-build-desktop/tst...
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot
in slot

kartun
28th February 2011, 13:09
Ok, thanks for checking. Seems I cutted off something important that blocks my own execution queue ...
Thanks to non really informative description of Qt, I just messed up with wrong slot signatures.

wysota
28th February 2011, 20:55
Thanks to non really informative description of Qt, I just messed up with wrong slot signatures.
What's exactly non-informative?