[Interest] Interface with signals and slots
Jérôme Godbout
godboutj at amotus.ca
Fri Nov 30 22:44:17 CET 2018
For me, under Android target, it does fail for the linking. I was trying to add and interface for injecting property into object expose to Qml. I often want to add a subset of property to a model and I would have want to have to rewrite the same Q_PROPERTY() and changed signal over and over again.
But I guess I will stick with the ugly macro mess for now.
Would be nice to have a way to extend a QObject with defined class of property with get/set and changed signals that is not a QObject to avoid diamond inheritance since it could already inherit another QObject class.
For example I would have love to have interface for the dirty property so I could inject the property on many qobjects types I have without rewriting it every time. I can make the get/set/ protected value, but I still have to create the signals/slots/Q_PROPERTY every time. I use some macro but I find that ugly and error prone to forget one.
From: Konstantin Shegunov <kshegunov at gmail.com>
Sent: November 30, 2018 4:29 PM
To: Jérôme Godbout <godboutj at amotus.ca>
Cc: Interests Qt <interest at qt-project.org>
Subject: Re: [Interest] Interface with signals and slots
Hi,
This compiles for me:
class SignalInterface
{
public:
virtual void mysignal() = 0;
};
class SignalImplementer : public QObject, public SignalInterface
{
Q_OBJECT
signals:
void mysignal() override;
};
However putting signals into an interface I think is rather dubious, because you won't be able to connect through the interface. I.e. this:
SignalImplementer obj;
QObject::connect(this, &Session::opened, &obj, &SignalInterface::mysignal);
Is going to fail the static assertions in QObject::connect.
You could derive from QObject though and have them in an abstract class.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181130/4fee8aab/attachment.html>
More information about the Interest
mailing list