Qt DevDays 2011, Qt Quick Best Practices and Design Patterns: Girish Ramakrishnan

Qt Group · 11K views · 2013 · 53:12

Open on YouTube

Software architecture & designC, C++, Rust, Go & systems languagestalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering QML questions about reusable components, especially the default property alias trick for placing child items inside a template.

Recommended by 1 people across 1 different months, 2012 to 2015.

What it is

A 53-minute conference talk from Qt Developer Days 2011 in Munich, given by Girish Ramakrishnan. It walks through best practices and design patterns for building scalable Qt Quick applications with QML and C++.

What people said

Recommends leemes · 2012-10 · Stack Overflow · on “How to define a "template" with child placeholders in QML?”

I found a much nicer answer to this question, suggested in a presentation of the Qt Developer Days 2011 "Qt Quick Best Practices and Design Patterns" [this video] . They use default property alias ... to alias the child items to any property of any item. If you don't want to alias the children but give the alias property a name, just remove default . (Literal children are per QML definition the value of the default property.) Item { id: button default property alias contents: placeholder.children anchors.fill: parent Rectangle { anchors.fill: parent radius: 10 color: "gray" Item { id: placeholder <-- where the placeholder should be inserted } } }

Cites Evgeny Timoshenko · 2014-05 · Stack Overflow · on “QQuickWidget and C++ interaction”

Give it a try: view->rootContext()->setContextProperty("test", "some random text"); instead of view->setProperty("test", 0); setProperty(name, val) [LINK] works if object has the property name defined as Q_PROPERTY . It is possible to pass QObject -derived object as view 's context property: class Controller : public QObject { Q_OBJECT QString m_test; public: explicit Controller(QObject *parent = 0); Q_PROPERTY(QString test READ test WRITE setTest NOTIFY testChanged) QDate test() const { return m_test; } signals: void testChanged(QString arg); public slots: void setTest(QDate arg) { if (m_test != arg) { m_test = arg; emit testChanged(arg); } } }; Controller c; view->rootContext()->setContext

Cites BaCaRoZzo · 2015-08 · Stack Overflow · on “Element inheritance not working”

Using absolute positioning is not advised. You can exploit a positioning type (e.g. Column ) to automatically lay out your items. However you have to ensure that, while added to BaseFrame.qml , Item s are correctly inserted in the positioning item. When Item s are added to a parent, they are inserted inside the default [LINK] property. In each Item -derived type, data [LINK] property is the default one. Then we alias the data of the positioning Item and then make that alias the default property. This way we obtain the result searched in the previous paragraph. The BaseFrame.qml could look like this: import QtQuick 2.0 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 Item { id: base anc