[Interest] Are slots even needed these days?

d3fault d3faultdotxbe at gmail.com
Sat May 7 09:34:17 CEST 2016


Nobody's mentioned that Qt4-style connect syntax is required to solve the
diamond inheritance problem that frequently appears when using a
signals/slots interface.

Ex:

class Interface
{
public:
    virtual QObject* asQObject()=0;
protected: //signals
    virtual void someSignal()=0;
public: //slots
    virtual void someSlot()=0;
};
class A : public QObject, public Interface
{
Q_OBJECT
public:
    QObject* asQObject() { return this; }
signals:
    void someSignal();
public slots:
    void someSlot();
};
class B : public QObject, public Interface
{
Q_OBJECT
public:
    QObject* asQObject() { return this; }
signals:
    void someSignal();
public slots:
    void someSlot();
};

int main()
{
    Interface *a = new A;
    Interface *b = new B;
    connect(a->asQObject(), SIGNAL(someSignal()), b->asQObject(),
SLOT(someSlot())); //not possible using Qt5 style connect syntax, because
someSignal and someSlot are not members of QObject
}


^code is pseudo/buggy, but mostly correct. also I'm aware that this
oversimplified example wouldn't suffer from the diamond inheritance
problem... but the diamond inheritance problem does frequently show up when
using signals/slots interfaces, so the above is usually what a solution
looks like


d3fault
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160507/ec2f8d03/attachment.html>


More information about the Interest mailing list