「Qtの基礎 - プリプロセッサ」の版間の差分

130行目: 130行目:
     }
     }
  };
  };
</syntaxhighlight>
<br>
== Q_GADGET ==
<code>QObject</code>クラスを継承せずに、Qtのメタオブジェクトシステムの一部の機能 (プロパティ、列挙型等) を利用可能にするマクロである。<br>
<br>
軽量なオブジェクトを作成する場合に有効である。<br>
<br>
<syntaxhighlight lang="c++">
class Point
{
    Q_GADGET
    Q_PROPERTY(int x MEMBER m_x)
    Q_PROPERTY(int y MEMBER m_y)
private:
    int m_x,
        m_y;
public:
    Point(int x = 0, int y = 0) : m_x(x), m_y(y) {}
    int x() const { return m_x; }
    int y() const { return m_y; }
};
Q_DECLARE_METATYPE(Point)
  </syntaxhighlight>
  </syntaxhighlight>
<br><br>
<br><br>