parent
c87171f443
commit
290650aae0
@ -0,0 +1,73 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
@ -0,0 +1,27 @@
|
||||
QT += quick
|
||||
|
||||
# You can make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
applicationbridge.cpp \
|
||||
dataobject.cpp \
|
||||
main.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 += \
|
||||
applicationbridge.h \
|
||||
dataobject.h
|
@ -0,0 +1,128 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
|
||||
Flow{
|
||||
anchors.fill: parent
|
||||
spacing: 0
|
||||
|
||||
//Connections
|
||||
Connections{
|
||||
target: window
|
||||
|
||||
onClicked1: {
|
||||
console.log("Reciever","onClicked1 in connection","Do something")
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
width: parent.width/2
|
||||
height: parent.height/2
|
||||
border.color: "#F5F5F5"
|
||||
|
||||
ColumnLayout{
|
||||
anchors.fill: parent
|
||||
|
||||
Button{
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
highlighted: true
|
||||
text: "Click"
|
||||
|
||||
onClicked: {
|
||||
window.clicked1()
|
||||
ApplicationBridge.action1()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle{
|
||||
width: parent.width/2
|
||||
height: parent.height/2
|
||||
border.color: "#F5F5F5"
|
||||
ColumnLayout{
|
||||
anchors.centerIn: parent
|
||||
|
||||
TextField{
|
||||
id: textfield
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
Layout.preferredHeight: 48
|
||||
text: ApplicationBridge.inputForCpp
|
||||
|
||||
onTextChanged: {
|
||||
ApplicationBridge.inputForCpp= text
|
||||
}
|
||||
}
|
||||
|
||||
Label{
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: textfield.width
|
||||
Layout.preferredHeight: 48
|
||||
wrapMode: "WrapAnywhere"
|
||||
elide: "ElideRight"
|
||||
maximumLineCount: 3
|
||||
|
||||
//value
|
||||
text: "C++ Property: " + ApplicationBridge.inputForCpp
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle{
|
||||
width: parent.width/2
|
||||
height: parent.height/2
|
||||
border.color: "#F5F5F5"
|
||||
ColumnLayout{
|
||||
anchors.fill: parent
|
||||
|
||||
ColumnLayout{
|
||||
anchors.centerIn: parent
|
||||
|
||||
Label{
|
||||
id: clockLabel
|
||||
Layout.preferredHeight: 48
|
||||
wrapMode: "WrapAnywhere"
|
||||
elide: "ElideRight"
|
||||
maximumLineCount: 3
|
||||
|
||||
Connections{
|
||||
target: ApplicationBridge
|
||||
|
||||
onTimeChanged: {
|
||||
clockLabel.text= "C++ Clock: " + dateFromCPP
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle{
|
||||
width: parent.width/2
|
||||
height: parent.height/2
|
||||
border.color: "#F5F5F5"
|
||||
ListView{
|
||||
anchors.fill: parent
|
||||
spacing: 2
|
||||
clip: true
|
||||
header: Label{
|
||||
width: parent.width
|
||||
text: "C++ Data model"
|
||||
horizontalAlignment: "AlignHCenter"
|
||||
}
|
||||
|
||||
model: ApplicationBridge.list
|
||||
delegate: Rectangle{
|
||||
id: modelDelegate
|
||||
width: parent.width
|
||||
height: 48
|
||||
color: modelData.color
|
||||
|
||||
Label{
|
||||
anchors.fill: parent
|
||||
text: modelData.name
|
||||
horizontalAlignment: "AlignHCenter"
|
||||
verticalAlignment: "AlignVCenter"
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
#include "applicationbridge.h"
|
||||
#include "dataobject.h"
|
||||
|
||||
ApplicationBridge::ApplicationBridge(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
QTimer *timer= new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(timerSlot()));
|
||||
timer->start(1000);
|
||||
|
||||
setList({
|
||||
new DataObject("Item 1", "red"),
|
||||
new DataObject("Item 2", "green"),
|
||||
new DataObject("Item 3", "blue"),
|
||||
new DataObject("Item 4", "yellow")
|
||||
});
|
||||
}
|
||||
|
||||
const QString &ApplicationBridge::inputForCpp() const
|
||||
{
|
||||
return m_inputForCpp;
|
||||
}
|
||||
|
||||
void ApplicationBridge::setInputForCpp(const QString &newInputForCpp)
|
||||
{
|
||||
if (m_inputForCpp == newInputForCpp)
|
||||
return;
|
||||
m_inputForCpp = newInputForCpp;
|
||||
emit inputForCppChanged();
|
||||
|
||||
qWarning()<<"Set in cpp"<<" "<<newInputForCpp;
|
||||
}
|
||||
|
||||
const QList<QObject *> &ApplicationBridge::list() const
|
||||
{
|
||||
return m_list;
|
||||
}
|
||||
|
||||
void ApplicationBridge::setList(const QList<QObject *> &newList)
|
||||
{
|
||||
if (m_list == newList)
|
||||
return;
|
||||
m_list = newList;
|
||||
emit listChanged();
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef APPLICATIONBRIDGE_H
|
||||
#define APPLICATIONBRIDGE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
|
||||
class ApplicationBridge : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString inputForCpp READ inputForCpp WRITE setInputForCpp NOTIFY inputForCppChanged)
|
||||
Q_PROPERTY(QList<QObject *> list READ list WRITE setList NOTIFY listChanged)
|
||||
|
||||
public:
|
||||
explicit ApplicationBridge(QObject *parent = nullptr);
|
||||
|
||||
const QString &inputForCpp() const;
|
||||
void setInputForCpp(const QString &newInputForCpp);
|
||||
|
||||
QString m_inputForCpp;
|
||||
|
||||
//Accessible function from c++
|
||||
Q_INVOKABLE void action1(){
|
||||
qWarning()<<"Take action 1";
|
||||
}
|
||||
const QList<QObject *> &list() const;
|
||||
void setList(const QList<QObject *> &newList);
|
||||
|
||||
signals:
|
||||
void inputForCppChanged();
|
||||
void timeChanged(QDateTime dateFromCPP);
|
||||
|
||||
void listChanged();
|
||||
|
||||
public slots:
|
||||
void timerSlot(){
|
||||
emit timeChanged(QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
private:
|
||||
QList<QObject *> m_list;
|
||||
};
|
||||
|
||||
#endif // APPLICATIONBRIDGE_H
|
@ -0,0 +1,38 @@
|
||||
#include "dataobject.h"
|
||||
|
||||
DataObject::DataObject(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
}
|
||||
|
||||
DataObject::DataObject(QString name, QString color)
|
||||
{
|
||||
setName(name);
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
const QString &DataObject::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void DataObject::setName(const QString &newName)
|
||||
{
|
||||
if (m_name == newName)
|
||||
return;
|
||||
m_name = newName;
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
const QString &DataObject::color() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void DataObject::setColor(const QString &newColor)
|
||||
{
|
||||
if (m_color == newColor)
|
||||
return;
|
||||
m_color = newColor;
|
||||
emit colorChanged();
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef DATAOBJECT_H
|
||||
#define DATAOBJECT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DataObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
|
||||
public:
|
||||
explicit DataObject(QObject *parent = nullptr);
|
||||
explicit DataObject(QString name, QString color);
|
||||
|
||||
const QString &name() const;
|
||||
void setName(const QString &newName);
|
||||
|
||||
const QString &color() const;
|
||||
void setColor(const QString &newColor);
|
||||
|
||||
QString m_name;
|
||||
QString m_color;
|
||||
signals:
|
||||
|
||||
void nameChanged();
|
||||
void colorChanged();
|
||||
};
|
||||
|
||||
#endif // DATAOBJECT_H
|
@ -0,0 +1,29 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include "applicationbridge.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#endif
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
ApplicationBridge appBridgeObject;
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
//Register c++ class to qml
|
||||
engine.rootContext()->setContextProperty("ApplicationBridge", &appBridgeObject);
|
||||
|
||||
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||
&app, [url](QObject *obj, const QUrl &objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-1);
|
||||
}, Qt::QueuedConnection);
|
||||
engine.load(url);
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
|
||||
//Window is accessible from everwhere, so we can use 'window' everywhere
|
||||
Window {
|
||||
id: window
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("CPP Backend")
|
||||
|
||||
//Signal
|
||||
signal clicked1()
|
||||
|
||||
onClicked1: {
|
||||
console.log("Reciever","onClicked1","Do something")
|
||||
}
|
||||
|
||||
Home{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>Home.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
Loading…
Reference in new issue