If I try to connect a button with a slot, the compiler told me:
QObject::connect: No such slot ClassA::..
ClassB inherit of ClassA. In ClassB I create a button and I will connecting it to a function in ClassB.
connect(btn, SIGNAL(clicked()), this, SLOT(helloWorld()));
The reason is, this is mean ClassA. How can i told the compiler, dont search for helloWorld() in ClassA and use the function helloWorld() in ClassB?
//header of classa
class ClassA : public QDialog
{
Q_OBJECT
public:
ClassA(QObject *parent = 0);
};
//header of classb
class ClassB : public ClassA
{
public:
ClassB();
public slots:
void helloWorld();
};
//cpp of classa
ClassA::ClassA(QObject *parent)
{
}
//cpp of classb
ClassB::ClassB()
{
QPushButton *btn = new QPushButton("Click");
connect(btn, SIGNAL(clicked()), this, SLOT(helloWorld()));
QHBoxLayout *l = new QHBoxLayout();
l->addWidget(btn);
setLayout(l);
}
void ClassB::helloWorld()
{
qDebug() << "hello world";
}