Add an example of Cpp model for views.

Remove qml folder.
Update SDK
This commit is contained in:
Julien Wadel 2023-10-03 15:44:20 +02:00
parent 4f86e1362a
commit 23c0b9bd42
11 changed files with 87 additions and 27 deletions

View file

@ -2,11 +2,17 @@
#include <QCoreApplication> #include <QCoreApplication>
#include "tool/Constants.hpp"
#include "view/Page/LoginPage.hpp"
App::App(QObject * parent) : QObject(parent) { App::App(QObject * parent) : QObject(parent) {
init(); init();
} }
//-----------------------------------------------------------
// Initializations
//-----------------------------------------------------------
void App::init() { void App::init() {
// Core // Core
@ -16,7 +22,9 @@ void App::init() {
mEngine = new QQmlApplicationEngine(this); mEngine = new QQmlApplicationEngine(this);
mEngine->addImportPath(":/"); mEngine->addImportPath(":/");
const QUrl url(u"qrc:/Linphone/view/qml/App/Main.qml"_qs); initCppInterfaces();
const QUrl url(u"qrc:/Linphone/view/App/Main.qml"_qs);
QObject::connect(mEngine, &QQmlApplicationEngine::objectCreated, QObject::connect(mEngine, &QQmlApplicationEngine::objectCreated,
this, [url](QObject *obj, const QUrl &objUrl) { this, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) if (!obj && url == objUrl)
@ -24,3 +32,9 @@ void App::init() {
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
mEngine->load(url); mEngine->load(url);
} }
void App::initCppInterfaces() {
qmlRegisterSingletonType<LoginPage>(Constants::MainQmlUri, 1, 0, "LoginPageCpp", [](QQmlEngine *engine, QJSEngine *) -> QObject *{
return new LoginPage(engine);
});
}

View file

@ -9,6 +9,7 @@ public:
App(QObject * parent = nullptr); App(QObject * parent = nullptr);
void init(); void init();
void initCppInterfaces();
QQmlApplicationEngine * mEngine = nullptr; QQmlApplicationEngine * mEngine = nullptr;
QSharedPointer<CoreModel> mCoreModel; QSharedPointer<CoreModel> mCoreModel;

View file

@ -12,7 +12,7 @@ Window {
ColumnLayout{ ColumnLayout{
anchors.fill: parent anchors.fill: parent
Login{ LoginPage{
height: 100 height: 100
width: 640 width: 640
} }

View file

@ -1,10 +1,15 @@
list(APPEND _LINPHONEAPP_QML_FILES list(APPEND _LINPHONEAPP_QML_FILES
view/qml/App/Main.qml view/App/Main.qml
view/qml/Item/Button.qml view/Item/Button.qml
view/qml/Page/Login.qml view/Page/LoginPage.qml
)
list(APPEND _LINPHONEAPP_SOURCES
view/Page/LoginPage.cpp
) )
set(_LINPHONEAPP_QML_FILES ${_LINPHONEAPP_QML_FILES} PARENT_SCOPE) set(_LINPHONEAPP_QML_FILES ${_LINPHONEAPP_QML_FILES} PARENT_SCOPE)
set(_LINPHONEAPP_SOURCES ${_LINPHONEAPP_SOURCES} PARENT_SCOPE)

View file

@ -27,10 +27,10 @@ Control.Button {
} }
hoverEnabled: true hoverEnabled: true
/*
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent
onPressed: mouse.accepted = false onPressed: mouse.accepted = false
} }*/
} }

View file

@ -0,0 +1,16 @@
#include "LoginPage.hpp"
#include <QTimer>
LoginPage::LoginPage(QObject * parent) : QObject(parent){
}
bool LoginPage::isLogged() {
static bool testLog = false;
QTimer::singleShot(2000, [&]() mutable{
testLog = true;
emit isLoggedChanged();
});
return testLog;
}

View file

@ -0,0 +1,17 @@
#include <QObject>
class LoginPage : public QObject{
Q_OBJECT
public:
LoginPage(QObject * parent = nullptr);
Q_PROPERTY(bool isLogged READ isLogged NOTIFY isLoggedChanged)
bool isLogged();
signals:
void isLoggedChanged();
};

View file

@ -0,0 +1,25 @@
import QtQuick 2.15
import QtQuick.Layouts 1.0
import Linphone
Item{
id: mainItem
ColumnLayout{
anchors.fill: parent
Text{
Layout.fillWidth: true
text: LoginPageCpp.isLogged ? "Online" : "Offline"
}
RowLayout{
Button{
text: 'Sign In'
onClicked: console.log("Click!")
}
Button{
text: 'Sign Out'
onClicked: console.log("Click!")
}
}
}
}

View file

@ -1,19 +0,0 @@
import QtQuick 2.15
import QtQuick.Layouts 1.0
import Linphone
Item{
id: mainItem
RowLayout{
Button{
text: 'Sign In'
}
Button{
text: 'Sign Out'
}
}
}

View file

@ -1,6 +1,7 @@
Qt6 application. Qt6 application.
export PATH=$PATH:~/Qt/6.5.2/gcc_64/bin export PATH=$PATH:~/Qt/6.5.2/gcc_64/bin
optional: export Qt6_DIR=~/Qt/6.5.2/gcc_64/lib/cmake/Qt6 optional: export Qt6_DIR=~/Qt/6.5.2/gcc_64/lib/cmake/Qt6
mkdir build mkdir build

@ -1 +1 @@
Subproject commit 0eb3d223aaee01b28d3f3d8c7dee4d0395782836 Subproject commit 521a001ab21f1127682333efce8d4a292099203c