2. Chi Sono ?
…un informatico
Seguo l’evoluzione del Qt Application Framework dal
lontano 2003
Nell’ottobre 2009 ho fondato la web community
www.qt-italia.org (chi vuol collaborare… serve aiuto!)
Qt day 2015 2
3. Dove va il mondo?
Qt day 2015 3
prototipazione (sempre
più) rapida
interaction
design
user experience
Internet of
things
Sempre più velocemente…
5. …ma da solo non basta…
In diverse occasioni si rende necessario estendere
QML con C++
Qt day 2015 5
6. Fonte: Qt Assistant 5.4
QML è stato progettato per essere esteso mediante C++
Le funzionalità C++ possono essere invocate da QML
Gli oggetti QML possono essere caricati e modificati da
C++
Qt day 2015 6
8. Esportare oggetti C++ a QML
Qt day 2015 8
The QQmlContext class defines a context within a QML engine.
proviamo a capire…
9. Esportare oggetti C++ a QML
The QQmlContext class defines a context within a QML engine.
#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
Qt day 2015 9
10. Esportare oggetti C++ a QML
#include <QQmlContext>
#include "label.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlContext *context=engine.rootContext();
Label label("Pippo");
context->setContextProperty("label",&label);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
Qt day 2015 10
The QQmlContext class defines a
context within a QML engine.
11. label.h
class Label : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
public:
explicit Label(QString name, QObject *parent = 0);
~Label();
QString name(){return m_name;};
void setName(QString newName){m_name=newName; emit nameChanged();};
signals:
void nameChanged();
public slots:
private:
QString m_name;
Qt day 2015 11
18. Esportare classi a QML
Types can be registered by calling qmlRegisterType() with an
appropriate type namespace and version number.
proviamo a capire…
Qt day 2015 18
24. E se facessi così ?
Item {
width: 320
height: 240
property alias button1: button1
//property alias label:label
Label {
id:label
name: "Pluto"
}
Qt day 2015 24
27. Esportare classi (GUI) a QML
The QQuickPaintedItem class provides a way to use the QPainter API
in the QML Scene Graph.
proviamo a capire…
Qt day 2015 27