Verified Commit 39f157c2 authored by Artem Sidyakin's avatar Artem Sidyakin
Browse files

Bunch of stuff

- [new demo] iOS sensors
- joined cpp-backend-qml demos in one folder
- updated imports in di demo
- feng-shui
parent 6a9df3b0
......@@ -10,7 +10,8 @@ A set of rather simple projects that demonstrate various Qt features.
- [GUI approaches](#gui-approaches)
- [Profiling](#profiling)
- [Webengine Recipes](#webengine-recipes)
- [C++ library as a backend for QML](#c-library-as-a-backend-for-qml)
- [C++ as a backend for QML](#c-as-a-backend-for-qml)
- [iOS sensors](#ios-sensors)
## Open Source API
......@@ -44,9 +45,12 @@ A bit modified standard WebEngine example.
<img src="/img/webengine-recipes.png" width="800">
## C++ library as a backend for QML
## C++ as a backend for QML
How to add an external C++/Qt library into the project and use it as a backend for QML-based frontend.
How to add an external C++/Qt library into the project and use it as a backend for QML-based frontend:
* variation with C++ library;
* variation with QML UI form.
<img src="/img/cpp-library-as-a-backend-for-qml.png" width="800">
......@@ -55,3 +59,9 @@ How to add an external C++/Qt library into the project and use it as a backend f
Anchoring and reparenting demo.
<img src="/img/anchoring.png" width="800">
## iOS sensors
Qt Sensors API on iOS with orientation sensor as an example.
<img src="/img/ios-sensors.png" width="800">
import QtQuick 2.11
import QtQuick.Controls 2.4
Page {
width: 600
height: 400
property alias btn_callBackend: btn_callBackend
header: Label {
text: qsTr("Page 1")
font.pixelSize: Qt.application.font.pixelSize * 2
padding: 10
}
Label {
id: lbl
text: qsTr("You are on Page 1.")
anchors.centerIn: parent
}
Button {
id: btn_callBackend
anchors.top: lbl.bottom
anchors.topMargin: 15
anchors.horizontalCenter: parent.horizontalCenter
text: "Call backend"
}
}
import QtQuick 2.11
import QtQuick.Controls 2.4
Page {
width: 600
height: 400
header: Label {
text: qsTr("Page 2")
font.pixelSize: Qt.application.font.pixelSize * 2
padding: 10
}
Label {
text: qsTr("You are on Page 2.<br/>Nothing happens here")
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.centerIn: parent
}
}
#include "ckhdbinterface.h"
CKHDBInterface::CKHDBInterface(QObject *parent) : QObject(parent)
{
}
QString CKHDBInterface::setDBValue()
{
return "something from backend";
}
#ifndef CKHDBINTERFACE_H
#define CKHDBINTERFACE_H
#include <QObject>
class CKHDBInterface : public QObject
{
Q_OBJECT
public:
explicit CKHDBInterface(QObject *parent = nullptr);
public slots:
QString setDBValue();
public slots:
};
#endif // CKHDBINTERFACE_H
QT += quick
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
ckhdbinterface.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
ckhdbinterface.h
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "ckhdbinterface.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
qmlRegisterType<CKHDBInterface>("kh.CKHDBInterface", 1, 0, "CKHDBInterface");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) { return -1; }
return app.exec();
}
import QtQuick 2.11
import QtQuick.Controls 2.4
import kh.CKHDBInterface 1.0
ApplicationWindow {
visible: true
width: 900
height: 600
title: qsTr("C++ backend for QML UI")
CKHDBInterface {
id: dbIF
}
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
Page1Form {
btn_callBackend {
onClicked: {
console.log(dbIF.setDBValue());
}
}
}
Page2Form { }
}
footer: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("Page 1")
}
TabButton {
text: qsTr("Page 2")
}
}
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>Page1Form.ui.qml</file>
<file>Page2Form.ui.qml</file>
<file>qtquickcontrols2.conf</file>
</qresource>
</RCC>
; This file can be edited to change the style of the application
; Read "Qt Quick Controls 2 Configuration File" for details:
; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html
[Controls]
Style=Default
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment