QT - Modern User Interfaces For C++ - Milian Wolff - CppCon 2015

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

MODERN USER INTERFACES FOR C++

Milian Wolff / KDAB


OUTLINE
Introduction
Widgets
QML / Quick
Essentials & Addons
Misconceptions
1. INTRODUCING QT
THE C++ UI FRAMEWORK
20+ years of innovation
thousands of developers
CROSS PLATFORM
Windows
Mac OS & iOS
Linux & Android
QNX

WHY I LIKE QT
C++
simple, consistent API
excellent documentation
open governance
versatile
practical
WHAT I DISLIKE ABOUT QT
code legacy
performance traps
lack of work with isocpp
2. QT WIDGETS
KMail
https://projects.kde.org/kdepim
Spotify on Linux
Krita
https://projects.kde.org/calligra
USING QT WIDGETS

Qt Creator and Qt Designer


http://code.qt.io/cgit/qt-creator/qt-creator.git
// generated by uic
#include <ui_mainwindow.h>
// part of KF5::ItemModels
#include <KRecursiveFilterProxyModel>

MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, m_ui(new Ui::MainWindow)
, m_treeModel(new MyTreeModel(this))
{
m_ui->setupUi(this);

auto proxy = new KRecursiveFilterProxyModel(this);


proxy->setSourceModel(m_treeModel);
m_ui->treeView->setModel(proxy);

connect(m_ui->treeFilter, &QLineEdit::textChanged,
proxy, &KRecursiveFilterProxyModel::setFilterRegExp);
}
QT WIDGETS
proven technology
perfect for desktop applications
not going to die anytime soon
contemporary, if not modern
3. QT QUICK
QT QUICK

import QtQuick 2.2


import QtQuick.Controls 1.4

ApplicationWindow {
visible: true
width: 400

Button {
text: "Check Me"
checkable: true

x: checked ? parent.width - width : 0


Behavior on x {
NumberAnimation {
duration: 1000
easing.type: Easing.OutBounce
}
}
}
}
declarative QML + JavaScript
hardware accelerated scene graph
trivial to create fancy animated UIs
perfect for embedded devices, phones
ideal for OpenGL overlays
only for representation
data and logic in C++
keep JavaScript to minimum
4. ESSENTIALS & ADDONS
QT THE TOOLKIT
mix and match with Boost, STL & others
signals & slots
unicode strings
any type wrapper
filesystem access
networking
state machines
localization
accessibility
date & time
settings
JSON
XML
SQL
...
QT THE TOOLKIT CONT'D
2D painting
OpenGL & 3D
modern HTML
printing
testing
serial ports
sensors
multimedia
location
bluetooth
NFC
...
KDE FRAMEWORKS 5
api.kde.org/frameworks-api/frameworks5-apidocs
compressed IO
model/view addons
advanced i18n
task based threading
hardware integration
spell checking
plotting
more widgets
configuration
...
INQLUDE.ORG
listing of additional Qt libraries
easy installation of libraries via command line
add what's missing!
5. MISCONCEPTIONS
code generators
containers
C++11
development process
QT CODE GENERATORS

moc
uic
rcc
...
improve productivity
simplify code maintenance
overcome C++ limitations
BUILD SYSTEM INTEGRATION
QMake
CMake
Visual Studio
MOC: REFLECTION

limited C++ parser to extract annotations


generates QMetaObjectfor reflection:
class name
inheritance chain
signals
slots
basisinvokable
for QML, methods
DBUS, WebChannel, Remote Objects
moc is not required anymore for slots
#include <QCoreApplication>
#include <QDebug>

int main(int argc, char** argv)


{
QCoreApplication app{argc, argv};

// execute lambda with 1s delay


QTimer::singleShot(1000 /*msec*/, [&] () {
qDebug() << "The time has come!";
app.quit();
});

return app.exec();
}
EFFICIENCY
200% Relative Size

7.1e+5

5.8e+4
2.3e+7

2.4e+4
2.3e+4
100%

3.7e+5
1.2e+7

2.9e+4
1.1e+7

3.3e+5

1.3e+4

2.8e+4
Data Segment
0%
text data bss relocations
QtGui (4.8.7)
QtGui & QtWidgets (5.5.0)
CsGui (1.2.1)
QT CONTAINERS

QList
QVector
QMap
QHash
...
understand implicit sharing
prefer to use QVectoror QHash
STL / Boost containers are also fine!
QListshould die
C++11 & QT
internally:
C++11 optionally used up to Qt 5.6
Qt 5.7+ will depend on a C++11 compiler
in your own applications:
use the latest and greatest C++XY
DEVELOPMENT PROCESS
open governance
FOSS & commercial license
KDE Free Qt Foundation
CLA
QUESTIONS?
[email protected]
http://www.kdab.com

What’s new in C++11 and C++14?


C++ trainings run by KDAB

You might also like