Falkon Develop
Cross-platform Qt-based web browser
qmltesthelper.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmltesthelper.h"
19#include "qml/qmlplugins.h"
20#include <QQmlComponent>
21#include <QDebug>
22
24{
26 qmlRegisterType<QmlTestItem>("org.kde.falkon.test", 1, 0, "TestItem");
27 QQmlComponent component(&engine);
28 component.setData("import org.kde.falkon 1.0 as Falkon\n"
29 "import org.kde.falkon.test 1.0 as FalkonTest\n"
30 "import QtQuick 2.7\n"
31 "FalkonTest.TestItem {"
32 " evalFunc: function(source) {"
33 " return eval(source);"
34 " }"
35 "}"
36 , QUrl());
37 testItem = qobject_cast<QmlTestItem*>(component.create());
38 Q_ASSERT(testItem);
39}
40
41QJSValue QmlTestHelper::evaluate(const QString &source)
42{
43 auto out = testItem->evaluate(source);
44 if (out.isError()) {
45 qWarning() << "Error:" << out.toString();
46 }
47 return out;
48}
49
50QObject *QmlTestHelper::evaluateQObject(const QString &source)
51{
52 auto out = evaluate(source);
53 if (out.isQObject()) {
54 return out.toQObject();
55 }
56 return out.toVariant().value<QObject*>();
57}
static void registerQmlTypes()
Definition: qmlplugins.cpp:57
QObject * evaluateQObject(const QString &source)
QJSValue evaluate(const QString &source)
QQmlEngine engine
Definition: qmltesthelper.h:29
QmlTestItem * testItem
Definition: qmltesthelper.h:30
QJSValue evaluate(const QString &source)
Definition: qmltestitem.cpp:35