mp/ Example of setting QML property from C++

This commit is contained in:
Tal Lancaster
2017-01-18 12:36:50 -07:00
parent c98a963ae0
commit 7fdb2ff111
4 changed files with 67 additions and 1 deletions
+17
View File
@@ -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)
+34
View File
@@ -0,0 +1,34 @@
/***
Simple example showing how to set properties.
item->setWidth (300);
rect->setProperty ("color", "red");
1/17/17 -- Tal Lancaster
***/
#include <QGuiApplication>
#include <QQuickView>
#include <QtQuick>
#include <QtQml>
#include <QtCore>
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<QObject*> ("rect");
if (rect) {
rect->setProperty ("color", "red");
}
return q_app.exec ();
}