Add 00_HelloWorld qt tutorial.
This commit is contained in:
1
qt/00_HelloWorld/.gitignore
vendored
Normal file
1
qt/00_HelloWorld/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build/
|
||||
44
qt/00_HelloWorld/CMakeLists.txt
Normal file
44
qt/00_HelloWorld/CMakeLists.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(00_HelloWorld LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt5 REQUIRED COMPONENTS Core Gui Qml Quick)
|
||||
find_package(LinphoneCxx REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
SET(CMAKE_AUTOUIC ON)
|
||||
|
||||
set(SOURCES
|
||||
"src/main.cpp"
|
||||
"src/CoreManager.cpp"
|
||||
)
|
||||
set(QRC_RESOURCES resources.qrc)
|
||||
set(QML_SOURCES)
|
||||
file(STRINGS ${QRC_RESOURCES} QRC_RESOURCES_CONTENT)
|
||||
foreach(line ${QRC_RESOURCES_CONTENT})
|
||||
set(result)
|
||||
string(REGEX REPLACE
|
||||
"^[ \t]*<[ \t]*file[ \t]*>[ \t]*(.+\\.[a-z]+)[ \t]*<[ \t]*/[ \t]*file[ \t]*>[ \t]*$"
|
||||
"\\1"
|
||||
result
|
||||
"${line}"
|
||||
)
|
||||
string(REGEX MATCH "\\.[a-z]+$" is_ui ${result})
|
||||
if(NOT ${is_ui} STREQUAL "")
|
||||
list(APPEND QML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${result}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_executable(00_HelloWorld ${SOURCES} ${QML_SOURCES} ${QRC_RESOURCES})
|
||||
|
||||
target_include_directories(00_HelloWorld PRIVATE ${LINPHONECXX_INCLUDE_DIRS})
|
||||
target_link_libraries(00_HelloWorld PRIVATE Qt5::Core Qt5::Gui Qt5::Qml Qt5::Quick ${LINPHONECXX_LIBRARIES})
|
||||
|
||||
set_target_properties(00_HelloWorld PROPERTIES AUTORCC ON)
|
||||
set_target_properties(00_HelloWorld PROPERTIES
|
||||
WIN32_EXECUTABLE ON
|
||||
MACOSX_BUNDLE ON
|
||||
)
|
||||
15
qt/00_HelloWorld/README.md
Normal file
15
qt/00_HelloWorld/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Hello World tutorial
|
||||
|
||||
The purpose of this tutorial is to explain how to build a Qt app depending on the Linphone SDK and to create the `Core` object that all our APIs depends on.
|
||||
|
||||
The user interface will only display the `Core`'s version, but in the next tutorial you will learn how to use it to login your SIP account.
|
||||
|
||||
|
||||
## How to build
|
||||
|
||||
In the following instructions, replace **<PATH-TO-SDK>** by the real path where your SDK is located, e.g. *~/projects/linphone-sdk/build-default/linphone-sdk/desktop/*
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_PREFIX_PATH=<PATH-TO-SDK>
|
||||
cmake --build .
|
||||
5
qt/00_HelloWorld/resources.qrc
Normal file
5
qt/00_HelloWorld/resources.qrc
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>ui/MainPage.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
32
qt/00_HelloWorld/src/CoreManager.cpp
Normal file
32
qt/00_HelloWorld/src/CoreManager.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "CoreManager.hpp"
|
||||
|
||||
CoreManager *CoreManager::mInstance = nullptr;
|
||||
|
||||
CoreManager::CoreManager()
|
||||
{
|
||||
// Create a core from the factory.
|
||||
mCore = linphone::Factory::get()->createCore("", "", nullptr);
|
||||
}
|
||||
|
||||
CoreManager::~CoreManager()
|
||||
{
|
||||
mCore = nullptr;
|
||||
}
|
||||
|
||||
void CoreManager::init()
|
||||
{
|
||||
if (mInstance)
|
||||
return;
|
||||
mInstance = new CoreManager();
|
||||
}
|
||||
|
||||
CoreManager *CoreManager::getInstance()
|
||||
{
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
QString CoreManager::getVersion() const
|
||||
{
|
||||
// Get the version from the core.
|
||||
return QString::fromStdString(mCore->getVersion());
|
||||
}
|
||||
25
qt/00_HelloWorld/src/CoreManager.hpp
Normal file
25
qt/00_HelloWorld/src/CoreManager.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
#include <linphone++/linphone.hh>
|
||||
|
||||
class CoreManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString version READ getVersion CONSTANT)
|
||||
|
||||
public:
|
||||
static void init();
|
||||
static CoreManager *getInstance();
|
||||
|
||||
QString getVersion() const;
|
||||
|
||||
private:
|
||||
CoreManager();
|
||||
~CoreManager();
|
||||
|
||||
std::shared_ptr<linphone::Core> mCore = nullptr;
|
||||
|
||||
static CoreManager *mInstance;
|
||||
};
|
||||
28
qt/00_HelloWorld/src/main.cpp
Normal file
28
qt/00_HelloWorld/src/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <QDir>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include "CoreManager.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
app.setOrganizationName("Belledonne Communications");
|
||||
app.setOrganizationDomain("belledonne-communications.com");
|
||||
app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.load(QUrl("qrc:/ui/MainPage.qml"));
|
||||
if (engine.rootObjects().isEmpty())
|
||||
qFatal("Unable to open main window.");
|
||||
|
||||
// Initialize the CoreManager singleton and add it to the Qml context.
|
||||
CoreManager::init();
|
||||
auto coreManager = CoreManager::getInstance();
|
||||
QQmlContext *ctx = engine.rootContext();
|
||||
ctx->setContextProperty("coreManager", coreManager);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
18
qt/00_HelloWorld/ui/MainPage.qml
Normal file
18
qt/00_HelloWorld/ui/MainPage.qml
Normal file
@@ -0,0 +1,18 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
visible: true
|
||||
|
||||
title: "Hello World"
|
||||
width: 640
|
||||
height: 480
|
||||
|
||||
Text {
|
||||
id: versionText
|
||||
text: "Hello world, Linphone core version is " + coreManager.version // Get the version from the core manager.
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user