aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/snippets/qml/qtbinding/functions-qml/main.cpp
blob: 672ff3aaf2d7b2aae63b859c626f3e325132ac6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore>
#include <QtQuick>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

//![0]
// main.cpp
QQmlEngine engine;
QQmlComponent component(&engine, "MyItem.qml");
QObject *object = component.create();

QString returnedValue;
QString msg = "Hello from C++";
QMetaObject::invokeMethod(object, "myQmlFunction",
        Q_RETURN_ARG(QString, returnedValue),
        Q_ARG(QString, msg));

qDebug() << "QML function returned:" << returnedValue;
delete object;
//![0]
}