[Qt-interest] Derive slots from non-Qt-based classes
Stefan Bisplinghoff
bisplinghoff at hia.rwth-aachen.de
Tue Apr 28 16:01:23 CEST 2009
Hi all!
I use some base SomeBaseClass for certain functionality and subclass it
for further use. The subclasses, e.g., SomeDerivedClass, derive from my
SomeBaseClass and QWidget to display the information evaluated in SomeClass.
As one slot is equal in all subclasses, I would like to implement this
slot in the SomeBaseClass. However, this class certainly does not derive
from QObject as multiple inheritance of Qt-based classes is not
supported. Therefore I store the pointer to the instance of the
SomeDerivedClass and use its connect member function (which originates
from the other branch of the inheritance) inside SomeBaseClass.
Qt complains on connect time, that the slot in the SomeDerivedClass does
not exists and hence nothing is connected. The filthy way to solve this
is to reimplement the slot in the SomeDerivedClass and just executes the
parent slot in SomeBaseClass. I suppose, there must be another
possibility to get this working...
Below is example code, which clarifies my structure:
class SomeBaseClass
{
protected:
void* m_childInstance;
public:
SomeBaseClass(void* childInstance, QObject* signalSender)
: m_childInstance(childInstance)
{
((QObject*)(m_childInstance))->connect(
signalSender,
SIGNAL(changeSomething()),
(QObject*)m_childInstance, SLOT(onChangeSomething()),
Qt::QueuedConnection);
};
protected slots:
virtual void onChangeSomething()
{
do_something();
};
};
class SomeDerivedClass : public QWidget, public SomeBaseClass
{
public:
SomeDerivedClass()
: SomeBaseClass(this)
{ };
///////// Current way to get this working //////////
protected slots:
void onChangeSomething()
{
SomeBaseClass::onChangeSomething()
};
////////////////////////////////////////////////////
};
Thanks in advance!
Kind regards,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090428/bcd00694/attachment.bin
More information about the Qt-interest-old
mailing list