diff --git a/CMakeLists.txt b/CMakeLists.txt index 55719af..79b0989 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,10 @@ +cmake_minimum_required(VERSION 3.0) + # sets the PROJECT_NAME variable project(qmlApp) -cmake_minimum_required(VERSION 3.0) +add_definitions(-std=c++14) +set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall") set(CMAKE_AUTOMOC ON) @@ -15,6 +18,8 @@ add_executable(${PROJECT_NAME} ${SRC_LIST}) # links Qt5Core to the project executable target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Qml Qt5::Quick) +add_subdirectory (mp) + add_custom_target(copyQmlFiles ALL DEPENDS ${PROJECT} ${CMAKE_SOURCE_DIR}/qml COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/qml diff --git a/mp/CMakeLists.txt b/mp/CMakeLists.txt new file mode 100644 index 0000000..9a15a32 --- /dev/null +++ b/mp/CMakeLists.txt @@ -0,0 +1,17 @@ +# sets the PROJECT_NAME variable +project(mpApp) + +cmake_minimum_required(VERSION 3.0) + +set(CMAKE_AUTOMOC ON) + +find_package(Qt5 COMPONENTS Qml Quick REQUIRED) + +set(SRC_LIST mp.cpp) + +# add an executable based on the project name and source list +add_executable(${PROJECT_NAME} ${SRC_LIST}) + +# links Qt5Core to the project executable +target_link_libraries(${PROJECT_NAME} Qt5::Qml Qt5::Quick) + diff --git a/mp/mp.cpp b/mp/mp.cpp new file mode 100644 index 0000000..ab25b4b --- /dev/null +++ b/mp/mp.cpp @@ -0,0 +1,34 @@ +/*** + Simple example showing how to set properties. + item->setWidth (300); + rect->setProperty ("color", "red"); + + 1/17/17 -- Tal Lancaster + ***/ +#include +#include +#include +#include +#include + +int main (int argc, char* argv[]) +{ + + QGuiApplication q_app (argc, argv); + + // Using QQuickView + QQuickView view; + view.setSource(QUrl::fromLocalFile("../qml/itemRect.qml")); + view.show(); + QQuickItem* item {view.rootObject () }; + item->setWidth (300); + + QObject* rect = item->findChild ("rect"); + if (rect) { + rect->setProperty ("color", "red"); + } + + + return q_app.exec (); +} + diff --git a/qml/itemRect.qml b/qml/itemRect.qml new file mode 100644 index 0000000..3424703 --- /dev/null +++ b/qml/itemRect.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +Item { + width: 100; height: 100 + + Rectangle { + anchors.fill: parent + objectName: "rect" + } +}