title: Can Q_GADGET be the property of other Q_GADGET?
body: <p>When I tried to pass such object in qml to some QML component property, it's just crashed in release or hung up in debug on:</p>
  
  <pre><code>Currency&amp; operator=(const Currency&amp; that) = default;
  </code></pre>
  
  <p>currency.h:</p>
  
  <pre><code>#ifndef CURRENCY_H
  #define CURRENCY_H
  
  #include &lt;QObject&gt;
  
  class Currency
  {
      Q_GADGET
  
      Q_PROPERTY(QString name READ getName CONSTANT)
  
  public:
      Currency() : name("") {}
  
      Currency(const Currency&amp; that) = default;
      Currency&amp; operator=(const Currency&amp; that) = default;
  
      static Currency getUSD() {
          return Currency("USD");
      }
  
      QString getName() {
          return this-&gt;name;
      }
  
  private:
      Currency(const QString&amp; name) : name(name) {}
  
      QString name;
  };
  
  #endif // CURRENCY_H
  </code></pre>
  
  <p>money.h:</p>
  
  <pre><code>#ifndef MONEY_H
  #define MONEY_H
  
  #include &lt;QObject&gt;
  
  #include "currency.h"
  
  class Money {
      Q_GADGET
  
      Q_PROPERTY(int amount READ getAmount CONSTANT)
      Q_PROPERTY(Currency currency READ getCurrency CONSTANT)
  
  public:
      Money() :
          Money(0, Currency())
      {
  
      }
  
      Money(int amount, const Currency&amp; currency) :
          amount(amount),
          currency(currency)
      {
  
      }
  
  
      int getAmount() {
          return this-&gt;amount;
      }
  
      Currency getCurrency() {
          return this-&gt;currency;
      }
  
  private:
      int amount;
      Currency currency;
  };
  
  #endif // MONEY_H
  </code></pre>
  
  <p>factory.h:</p>
  
  <pre><code>#ifndef FACTORY_H
  #define FACTORY_H
  
  #include &lt;QObject&gt;
  #include &lt;QVariant&gt;
  
  #include "money.h"
  
  class Factory : public QObject {
      Q_OBJECT
      Q_DISABLE_COPY(Factory)
  
  public:
      static Factory* instance() {
          static Factory factory;
          return &amp;factory;
      }
  
      Q_INVOKABLE QVariant getMoney() {
          return QVariant::fromValue(Money(12345, Currency::getUSD()));
      }
  
  private:
      explicit Factory(QObject* parent = nullptr) :
          QObject(parent)
      {
  
      }
  };
  
  #endif // FACTORY_H
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QGuiApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  
  #include "factory.h"
  #include "money.h"
  
  
  int main(int argc, char *argv[])
  {
      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  
      QGuiApplication app(argc, argv);
  
      qmlRegisterUncreatableType&lt;Money&gt;("test", 1, 0, "Money", "error");
      qmlRegisterUncreatableType&lt;Currency&gt;("test", 1, 0, "Currency", "error");
      qmlRegisterSingletonType&lt;Factory&gt;("test", 1, 0, "Factory",
                                        [](QQmlEngine* engine, QJSEngine* scriptEngine) -&gt; QObject* {
          Q_UNUSED(scriptEngine)
  
          Factory* instance = Factory::instance();
          engine-&gt;setObjectOwnership(instance, QQmlEngine::ObjectOwnership::CppOwnership);
  
          return instance;
      });
  
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      if (engine.rootObjects().isEmpty())
          return -1;
  
      return app.exec();
  }
  </code></pre>
  
  <p>main.qml:</p>
  
  <pre><code>import QtQuick 2.11
  import QtQuick.Window 2.11
  
  import test 1.0
  
  Window {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
      MyItem {
          value: {
              var money = Factory.getMoney()
              console.log(money)
  
              return money
          }
  
          anchors.centerIn: parent
      }
  }
  </code></pre>
  
  <p>MyItem.qml:</p>
  
  <pre><code>import QtQuick 2.10
  import QtQuick.Controls 2.3
  
  
  Item {
      id: root
      property var value
  
      width: label.width
      height: label.height
  
      Component.onCompleted: {
          console.log(root.value)
      }
  
      Label {
          id: label
  
          text: root.value.currency.name
      }
  }
  </code></pre>