[Interest] [External] Interface with signals and slots (Jérôme Godbout)

Stan Morris pixelgrease at gmail.com
Tue Feb 19 03:43:49 CET 2019

Re: [External]  Interface with signals and slots
      (Jérôme Godbout)

Your sample code declares an abstract IMyInterface rather than a class
interface; there are concrete method declarations. If you make them pure
virtual methods, your code compiles. You must implement the interface
functions in the subclass... that's just the way it is. You can inherit
multiple interfaces by implementing the getter/setters in the subclass.

Here are code changes that work:

class IMyInterface



    explicit IMyInterface() {};

    virtual ~IMyInterface() {};

    virtual bool val() const = 0;

    virtual void setVal(const bool v) = 0;


    virtual void valChanged() const = 0;


class MyClass : public QObject, public IMyInterface



    Q_PROPERTY(bool val READ val WRITE setVal NOTIFY valChanged)



    MyClass() : m_val() {}

    bool val() const override { return m_val; }

    void setVal(const bool v) override


        if (v != m_val) {

            m_val = v;

            emit valChanged();




    virtual void valChanged() const override;


    bool m_val;


- Stan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190218/4577c9f3/attachment.html>

More information about the Interest mailing list