From 52edfb0e6b14b7fd6dd264e619505d11569503fb Mon Sep 17 00:00:00 2001 From: Rasim Labibov Date: Wed, 18 Oct 2017 14:47:07 +0300 Subject: [PATCH] Initial minimal project. --- CMakeLists.txt | 14 ++++++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 28 ++++++++++++++++++++++++++++ src/main.qml | 12 ++++++++++++ src/qml.qrc | 6 ++++++ src/qmldir | 2 ++ src/stdafx.h | 2 ++ 8 files changed, 153 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/main.cpp create mode 100644 src/main.qml create mode 100644 src/qml.qrc create mode 100644 src/qmldir create mode 100644 src/stdafx.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5e6fc05 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8) + +# Common project properties +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILT_TYPE Debug CACHE STRING "Choose the type of build, options are: Debug Release" FORCE) +endif() + +# 3rd party tools +find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED) + +# Directory with the source code +add_subdirectory(src) + + diff --git a/README.md b/README.md index e69de29..0a780e6 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,46 @@ +# Minimal Qt QML Project + +This is minimal program that uses Qt Qml for creating user interface library +and using CMake as build system. + +## Built With + +* [CMake](http://cmake.org/) - Build system (>=5.7 is required). +* [Qt](http://www.qt.io/) - Cross-platform library (>=2.8 is required). + +## Getting Started + +Install the following packages to prepare the build. + +### Ubuntu & Debian + +* Ubuntu 16.04 +* Debian 9 + +``` +sudo apt-get install -y build-essential cmake qtbase5-dev qtdeclarative5-dev qml-module-qtquick2 qtquickcontrols2-5-dev qml-module-qtquick-controls +``` + +### Fedora & CentOS + +* CentOS 7 +* Fedora >=20 + +``` +sudo yum groupinstall -y "Development Tools" +sudo yum install -y cmake qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qtquickcontrols qt5-qtquickcontrols2-devel +``` + +### Build Solution + +Call the build of the solution and launch the application: + +``` +cd +mkdir build +cd build +cmake .. +make +./src/MinimalQml & +``` + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..af8e10e --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,43 @@ +include_directories(${Qt5Widgets_INCLUDE_DIRS} ${QtQml_INCLUDE_DIRS}) +add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} ${${Qt5Quick_DEFINITIONS}}) + +qt5_add_resources(QT_RESOURCES qml.qrc) + + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG") +endif() + + +set(PROJECT "MinimalQml") + +project(${PROJECT}) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -fstrict-aliasing -pedantic-errors -pedantic -Wno-deprecated-declarations -Wno-unused-variable") + +if(NOT DEFINED HEADERS) + file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) +endif() + +if(NOT DEFINED SOURCES) + file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +endif() + +source_group("Header Files" FILES ${HEADERS}) +source_group("Source Files" FILES ${SOURCES}) + + +add_executable(${PROJECT} ${HEADERS} ${SOURCES} ${QT_RESOURCES}) + +target_link_libraries(${PROJECT} + Qt5::Widgets + Qt5::Qml + Qt5::Quick + ) + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a255165 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,28 @@ +#include "stdafx.h" +#include +#include +#include + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + int result = 0; + + try + { + result = app.exec(); + } + catch(const std::exception& ex) + { + QString message = ex.what(); + QMessageBox::critical(nullptr, qtTrId("Error"), message); + result = -1; + } + + return result; +} + diff --git a/src/main.qml b/src/main.qml new file mode 100644 index 0000000..7d54acf --- /dev/null +++ b/src/main.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 + +ApplicationWindow +{ + visible: true + width: 640 + height: 480 + title: qsTr("Minimal Qml") +} + diff --git a/src/qml.qrc b/src/qml.qrc new file mode 100644 index 0000000..80b311d --- /dev/null +++ b/src/qml.qrc @@ -0,0 +1,6 @@ + + + qmldir + main.qml + + diff --git a/src/qmldir b/src/qmldir new file mode 100644 index 0000000..139597f --- /dev/null +++ b/src/qmldir @@ -0,0 +1,2 @@ + + diff --git a/src/stdafx.h b/src/stdafx.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/src/stdafx.h @@ -0,0 +1,2 @@ +#pragma once +