Turn CppUtils into a Singleton

This commit is contained in:
miruka 2019-12-27 08:58:24 -04:00
parent e7caa0b8ef
commit f34d2a1c6d
5 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import CppUtils 0.1
import "../../../Base" import "../../../Base"
HColumnLayout { HColumnLayout {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import CppUtils 0.1
import "../../../Base" import "../../../Base"
HTile { HTile {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import io.thp.pyotherside 1.5 import io.thp.pyotherside 1.5
import CppUtils 0.1
Python { Python {
id: py id: py

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12 import QtQuick 2.12
import CppUtils 0.1
QtObject { QtObject {
function makeObject(urlComponent, parent=null, properties={}, function makeObject(urlComponent, parent=null, properties={},

View File

@ -39,9 +39,19 @@ int main(int argc, char *argv[]) {
// Add our custom non-visual `QObject `s as properties. // Add our custom non-visual `QObject `s as properties.
// Their attributes and methods will be accessing like normal QML objects. // Their attributes and methods will be accessing like normal QML objects.
objectContext->setContextProperty("CppUtils", new Utils()); /* objectContext->setContextProperty("CppUtils", new Utils()); */
objectContext->setContextProperty("Clipboard", new Clipboard()); objectContext->setContextProperty("Clipboard", new Clipboard());
qmlRegisterSingletonType<Utils>(
"CppUtils", 0, 1, "CppUtils",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Utils();
}
);
// Register our custom visual items that will be importable from QML, // Register our custom visual items that will be importable from QML,
// e.g. `import RadialBar 1.0` // e.g. `import RadialBar 1.0`
qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar"); qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar");