Important: Please read the Qt Code of Conduct -

Are there any samples or documentation on coding a Qt Quick application using C++?

  • Hi,

    I'm looking for sample applications for building a "Qt Quick" application with the UI written in C++ (versus QML which is more popular). Anyone has any insight into how to use QT Quick Controls directly from C++, preferably with references to sample projects and/or documentation?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Something's not quiet clear here. Do you want to build the whole UI from QML elements but generated in C++ ?

    Or if you're not interested in QML why not use the widget module ?

  • The texteditor example that ships with the SDK shows you how to do this, basically you register your C++ back end like:
    qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");

    Then derive your class from QObject, and use Q_PROPERTY:
    Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)

    To access the code from QML.

    There are other methods of doing this, but this one is how they coded this example.

    "Interacting with QML Objects from C++":

    "Exposing Attributes of C++ Types to QML":

    What method is best practice or will be the latest and longest supported method is what I would like to know, the lack of documentation and examples is not helping matters much.

Log in to reply