'Notify Q_PROPERTY changes on a Q_GADGET class

I have this class that do not derive from QObject because I need it to be copyable:

#ifndef ITEM_HPP
#define ITEM_HPP

#include <QObject>

class Item
{
  Q_GADGET
  Q_PROPERTY(int intValue READ intValue WRITE setIntValue)
  Q_PROPERTY(QString stringValue READ stringValue WRITE setStringValue)

  public:
    Item();

    int intValue() const { return m_intValue; }
    void setIntValue(int intValue) { m_intValue = intValue; }

    const QString& stringValue() const { return m_stringValue; }
    void setStringValue(const QString& stringValue) { m_stringValue = stringValue; }

  private:
    int m_intValue;
    QString m_stringValue;
};

Q_DECLARE_METATYPE(Item)

#endif // ITEM_HPP

How can I notify the QML when intValue or stringValue changes?
If the class derived from QObject I could add the NOTIFY property, but how can I do this without deriving from QObject?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source