Added support for adding import paths.

This commit is contained in:
Paul Knopf 2018-07-19 11:05:19 -04:00
parent 19e0b4109a
commit fd3bccebbd
8 changed files with 31 additions and 7 deletions

View file

@ -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);
}
}

View file

@ -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<TestQmlImport>();
engine.AddImportPath(Path.Combine(Directory.GetCurrentDirectory(), "Qml"));
QQmlApplicationEngine.RegisterType<TestQmlImport>("test");

View file

@ -0,0 +1,8 @@
// factorial.js
function factorial(a) {
a = parseInt(a);
if (a <= 0)
return 1;
else
return a * factorial(a - 1);
}

Binary file not shown.

View file

@ -0,0 +1,2 @@
module MyModule
Factorial 1.0 factorial.js

View file

@ -12,8 +12,9 @@
<None Update="main.qml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Remove="Program.UI.cs" />
<None Include="Program.UI.cs" />
<Compile Remove="Program.Tests.cs" />
<None Include="Program.Tests.cs" />
<Compile Remove="Qml\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="xunit.core" Version="2.4.0" />

View file

@ -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))
}
}
}

View file

@ -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);
}
}