From fd3bccebbd0997641beb6084a7e8375768c475de Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Thu, 19 Jul 2018 11:05:19 -0400 Subject: [PATCH] Added support for adding import paths. --- .../QtNetCoreQml/qml/QQmlApplicationEngine.cpp | 5 +++++ src/net/Qt.NetCore.Sandbox/Program.UI.cs | 3 ++- .../Qt.NetCore.Sandbox/Qml/MyModule/factorial.js | 8 ++++++++ .../Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc | Bin 0 -> 768 bytes src/net/Qt.NetCore.Sandbox/Qml/MyModule/qmldir | 2 ++ .../Qt.NetCore.Sandbox/Qt.NetCore.Sandbox.csproj | 5 +++-- src/net/Qt.NetCore.Sandbox/main.qml | 7 +++---- src/net/Qt.NetCore/Qml/QQmlApplicationEngine.cs | 8 ++++++++ 8 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js create mode 100644 src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc create mode 100644 src/net/Qt.NetCore.Sandbox/Qml/MyModule/qmldir diff --git a/src/native/QtNetCoreQml/QtNetCoreQml/qml/QQmlApplicationEngine.cpp b/src/native/QtNetCoreQml/QtNetCoreQml/qml/QQmlApplicationEngine.cpp index 1cb11025..c53d828d 100644 --- a/src/native/QtNetCoreQml/QtNetCoreQml/qml/QQmlApplicationEngine.cpp +++ b/src/native/QtNetCoreQml/QtNetCoreQml/qml/QQmlApplicationEngine.cpp @@ -86,4 +86,9 @@ Q_DECL_EXPORT int qqmlapplicationengine_registerType(NetTypeInfoContainer* typeC return -1; } +Q_DECL_EXPORT void qqmlapplicationengine_addImportPath(QQmlApplicationEngineContainer* container, LPWSTR path) { + QString pathString = QString::fromUtf16((const char16_t*)path); + container->qmlEngine->addImportPath(pathString); +} + } diff --git a/src/net/Qt.NetCore.Sandbox/Program.UI.cs b/src/net/Qt.NetCore.Sandbox/Program.UI.cs index 79fdecc0..82538a45 100644 --- a/src/net/Qt.NetCore.Sandbox/Program.UI.cs +++ b/src/net/Qt.NetCore.Sandbox/Program.UI.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -51,7 +52,7 @@ namespace Qt.NetCore.Sandbox { using (var engine = new QQmlApplicationEngine()) { - var type = NetTypeManager.GetTypeInfo(); + engine.AddImportPath(Path.Combine(Directory.GetCurrentDirectory(), "Qml")); QQmlApplicationEngine.RegisterType("test"); diff --git a/src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js b/src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js new file mode 100644 index 00000000..1b1ba5a3 --- /dev/null +++ b/src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js @@ -0,0 +1,8 @@ +// factorial.js +function factorial(a) { + a = parseInt(a); + if (a <= 0) + return 1; + else + return a * factorial(a - 1); +} \ No newline at end of file diff --git a/src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc b/src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc new file mode 100644 index 0000000000000000000000000000000000000000..1efdbe07951ca49180b516b0984100e2667dc7a1 GIT binary patch literal 768 zcmaJ-u`dI06#lMtRjo7n;2`&o#0`SQKr`+e`d?{}@!Ld|mnHw(Z>n;5+Oyz>km;=o+d&lmH`nXx@b zIlf;g*-Cj;+p%p`vVFTWo39pYzM?ve&XXE{zt23}?p$A8yk>87U2{K^1o6iCG4dlJ z@!X>yeu>VSX+`XWA-xisMY9~$q`pg}h(1DMtw$ltPC0)u#77K6(d}=NdmYjz-jl?F zfnj6BNSXRF;($Cxh!ug}yTM$%2+LlX^WR?WThEtwix;V<38`lYnKKnL%(NM=m`m}b zft0zOPE5i`9O_<5&=oU$z$jr8A4HeXF~CH@MGXO(Xk(vwoi%yuG4nP$@Uemh?cM`b{6P#s{JTV#jNtc4@au-MaPRVyr1sLNqB)GtQr u9M PreserveNewest - - + + + diff --git a/src/net/Qt.NetCore.Sandbox/main.qml b/src/net/Qt.NetCore.Sandbox/main.qml index 4c405161..3deab883 100644 --- a/src/net/Qt.NetCore.Sandbox/main.qml +++ b/src/net/Qt.NetCore.Sandbox/main.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import test 1.0 +import MyModule 1.0 as MyModule ApplicationWindow { visible: true @@ -11,11 +12,9 @@ ApplicationWindow { Item { Timer { - interval: 10; running: true; repeat: true + interval: 1000; running: true; repeat: true onTriggered: { - var par = test.Create() - test.TestMethod(par) - gc() + console.log(Factorial.factorial(10)) } } } diff --git a/src/net/Qt.NetCore/Qml/QQmlApplicationEngine.cs b/src/net/Qt.NetCore/Qml/QQmlApplicationEngine.cs index 74a028e8..089e2117 100644 --- a/src/net/Qt.NetCore/Qml/QQmlApplicationEngine.cs +++ b/src/net/Qt.NetCore/Qml/QQmlApplicationEngine.cs @@ -29,6 +29,11 @@ namespace Qt.NetCore.Qml return Interop.QQmlApplicationEngine.RegisterType(type.Handle, uri, versionMajor, versionMinor, qmlName); } + public void AddImportPath(string path) + { + Interop.QQmlApplicationEngine.AddImportPath(Handle, path); + } + protected override void DisposeUnmanaged(IntPtr ptr) { Interop.QQmlApplicationEngine.Destroy(ptr); @@ -47,6 +52,9 @@ namespace Qt.NetCore.Qml [NativeSymbol(Entrypoint = "qqmlapplicationengine_registerType")] int RegisterType(IntPtr type, [MarshalAs(UnmanagedType.LPWStr)]string uri, int versionMajor, int versionMinor, [MarshalAs(UnmanagedType.LPWStr)]string qmlName); + + [NativeSymbol(Entrypoint = "qqmlapplicationengine_addImportPath")] + void AddImportPath(IntPtr engine, [MarshalAs(UnmanagedType.LPWStr)]string path); } } \ No newline at end of file