Load property from QML-file in C++

Hedge

I'm building a plugin-system for my QML+C++ application. The plugins are QML-files. A qml-file could look like this:

Item { title: "Sexy Plugin" version: "1.0" }

How can I read title and version within C++?

MattW

The easiest wold be, to write a QuickItem in C++. Even when its just a small component, that just holds title and version. Then it is easily accessible within C++ and its the cleanest way, to decouple view and logic.Then you can just define properties with the well-known Q_PROPERTY Macro.

If you actually want to use only Qml-written components and don't want to write anything in C++, there is a solution mentioned at this page: http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

Quoting the relevant part from "Accessing Members of a QML Object Type from C++":

QQmlEngine engine;
QQmlComponent component(&engine, "MyItem.qml");
QObject *object = component.create();

qDebug() << "Property value:" << QQmlProperty::read(object, "someNumber").toInt();
QQmlProperty::write(object, "someNumber", 5000);

qDebug() << "Property value:" << object->property("someNumber").toInt();
object->setProperty("someNumber", 100);

So QQmlProperty might help you.

As I don't know, what your goal is, I won't recommend anything. Anyway in my opinion, the first way of just writing the Item in C++ is in many cases much cleaner then trying to get the properties from Qml.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Load property from QML-file in C++

From Dev

QML Plugin load from C++

From Dev

Read property from QML singleton with C++

From Dev

Load qml component/file from local file system

From Dev

QML not registering property change from C++ property

From Dev

Load JPA repository queries from a property file

From Dev

How to load qml file from resources, using QtQuick 2 Controls

From Dev

Load and Inject to Property Bean from XML Property File with Spring

From Dev

Load and Inject to Property Bean from XML Property File with Spring

From Dev

How to load image from URL in QML not in QT C++

From Dev

Setting object type property in QML from C++

From Dev

Qt / QML set property from c++ class for GridView

From Dev

Qt / QML set property from c++ class for GridView

From Dev

load external qml file on android

From Dev

Include another QML file from a QML file

From Dev

QML TableView from file

From Dev

How to load property file from classpath in AWS lambda java

From Dev

Load property from external file into build.gradle

From Dev

load property file from external path using spring

From Dev

Load treegrid data dyanamically from a json property file in extjs

From Dev

Load property from external file into build.gradle

From Dev

How to create custom QML element from file in c++?

From Dev

C# Monogame - Load level from file

From Dev

how to load a c string from a file

From Dev

C : Load data from file to the linked list

From Dev

Call function or property in another QML File inside a TabView in QML

From Dev

QML - connect a signal from c++ to qml

From Dev

Error trying to load qml from resource

From Dev

Access property set with setProperty from QML

Related Related

HotTag

Archive