mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 14:55:34 -06:00
Added support for adding import paths.
This commit is contained in:
parent
19e0b4109a
commit
fd3bccebbd
8 changed files with 31 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
8
src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js
Normal file
8
src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// factorial.js
|
||||
function factorial(a) {
|
||||
a = parseInt(a);
|
||||
if (a <= 0)
|
||||
return 1;
|
||||
else
|
||||
return a * factorial(a - 1);
|
||||
}
|
||||
BIN
src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc
Normal file
BIN
src/net/Qt.NetCore.Sandbox/Qml/MyModule/factorial.jsc
Normal file
Binary file not shown.
2
src/net/Qt.NetCore.Sandbox/Qml/MyModule/qmldir
Normal file
2
src/net/Qt.NetCore.Sandbox/Qml/MyModule/qmldir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module MyModule
|
||||
Factorial 1.0 factorial.js
|
||||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue