Issues with connecting signal slot in case of multiple inheritance
Hi,
I am trying to map signal slot using QSignalMapper. The object I pass to the signalmapper is publicly derived from both QPushButton and CTest (CTest is not derived from any other class). CTest has only one int variable.
so the declaration of my class will be
class CClassy : public QPushButton,public CTest
{
}
Now when I set the signal slot using signalmapper and pass the object of CClassy, it doesn't work. But if I pass an object of QPushButton, the same setup works fine.
Is it because of Multiple inheritance?
Thanks
Re: Issues with connecting signal slot in case of multiple inheritance
Don't forget the Q_OBJECT macro in your class!
Re: Issues with connecting signal slot in case of multiple inheritance
I have Q_OBJECT macro in my class....
Re: Issues with connecting signal slot in case of multiple inheritance
Code:
#include <QtGui>
class Base
{
public:
int i;
};
{
Q_OBJECT
public:
int i;
};
int main(int argc, char* argv[])
{
MyButton b;
b.setText("Click to close!");
QObject::connect(&b,
SIGNAL(clicked
()),
&app,
SLOT(quit
()));
b.show();
return app.exec();
}
#include "main.moc"
works fine for me. Your error must be somewhere else.
Re: Issues with connecting signal slot in case of multiple inheritance
Didn't you forgot the Q_OBJECT macro: (my guess is that you did, because there is no other reason for that)
Code:
{
Q_OBJECT
//... rest of the class definition
}
EDIT: My answer was too late... sorry...
Re: Issues with connecting signal slot in case of multiple inheritance
Ya, this code works for me as well. So I guess the issue is with my code. Thanks for you time.
Re: Issues with connecting signal slot in case of multiple inheritance
Didn't the above example from Lykurg's work ?? Do you cast from one type to another in your code somewhere ???
Re: Issues with connecting signal slot in case of multiple inheritance
Ahh, I got the root cause of the issue. I was overriding mousepressevent() on my button class, but after doing my stuff, was not calling QPushButton::mousePressEvent(e). After adding that code, everything works fine.
Thanks everyone.
Re: Issues with connecting signal slot in case of multiple inheritance
Quote:
Originally Posted by
dpatel
Ahh, I got the root cause of the issue. I was overriding mousepressevent() on my button class, but after doing my stuff, was not calling QPushButton::mousePressEvent(e).
:D I "love" that kind of errors, they drive you crazy and you search everywhere but can't find anything. With this kind of errors I wast houres week after week!