实例介绍
qmlnet是一个将Qt/QML与.NET集成的项目。它支持多个平台和运行时环境,包括.NET Framework、.NET Core和Mono。
快速概述
//QmlType.cs using Qml.Net; using System.Threading.Tasks; namespace QmlQuickOverview { [Signal("customSignal", NetVariantType.String)] // You can define signals that Qml can listen to. public class QmlType { /// <summary> /// Properties are exposed to Qml. /// </summary> [NotifySignal("stringPropertyChanged")] // For Qml binding/MVVM. public string StringProperty { get; set; } /// <summary> /// Methods can return .NET types. /// The returned type can be invoked from Qml (properties/methods/events/etc). /// </summary> /// <returns></returns> public QmlType CreateNetObject() { return new QmlType(); } /// <summary> /// Qml can pass .NET types to .NET methods. /// </summary> /// <param name="parameter"></param> public void TestMethod(QmlType parameter) { } /// <summary> /// Async methods can be invoked with continuations happening on Qt's main thread. /// </summary> public async Task<string> TestAsync() { // On the UI thread await Task.Run(() => { // On the background thread }); // On the UI thread return "async result!"; } /// <summary> /// Qml can also pass Qml/C objects that can be invoked from .NET /// </summary> /// <param name="qObject"></param> public void TestMethodWithQObject(dynamic o) { string result = o.propertyDefinedInCpp; o.methodDefinedInCpp(result); // You can also listen to signals on QObjects. var qObject = o as INetQObject; var handler = qObject.AttachSignal("signalName", parameters => { // parameters is a list of arguements passed to the signal. }); handler.Dispose(); // When you are done listening to signal. // You can also listen to when a property changes (notify signal). handler = qObject.AttachNotifySignal("property", parameters => { // parameters is a list of arguements passed to the signal. }); handler.Dispose(); // When you are done listening to signal. } /// <summary> /// .NET can activate signals to send notifications to Qml. /// </summary> public void ActivateCustomSignal(string message) { this.ActivateSignal("customSignal", message); } } }
【核心代码】
文件清单
└── qmlnet-0836ae783a3ed5fb404db68d0706f9a7fa3765b4
├── appveyor.yml
├── build
│ ├── appveyor.bat
│ ├── common.props
│ ├── scripts
│ │ ├── Buildary
│ │ ├── Build.csproj
│ │ └── Program.cs
│ ├── travis.linux.sh
│ ├── travis.osx.sh
│ ├── travis.sh
│ └── version.props
├── build.bat
├── build.ps1
├── build.sh
├── GitVersion.yml
├── LICENSE
├── README.md
├── resources
│ └── logo.svg
├── samples
│ ├── hosting
│ │ ├── native
│ │ │ ├── main.cpp
│ │ │ ├── main.qml
│ │ │ ├── NativeHost.pro
│ │ │ ├── Page1Form.ui.qml
│ │ │ ├── Page2Form.ui.qml
│ │ │ ├── qml.qrc
│ │ │ └── qtquickcontrols2.conf
│ │ ├── net
│ │ │ ├── NetHost.csproj
│ │ │ ├── NetHost.sln
│ │ │ └── Program.cs
│ │ └── README.md
│ └── PhotoFrame
│ ├── ImagePool
│ │ ├── abandoned-forest-industry-34950.jpg
│ │ ├── agriculture-apple-blur-257840.jpg
│ │ ├── animal-animal-photography-big-cat-145939.jpg
│ │ ├── art-ball-ball-shaped-235615.jpg
│ │ ├── beautiful-bird-s-eye-view-boats-1039302.jpg
│ │ ├── clouds-cloudy-countryside-236047.jpg
│ │ └── mobilechallenge-4k-wallpaper-close-up-807598.jpg
│ ├── PhotoFrame.App
│ │ ├── PhotoFrame.App.csproj
│ │ ├── Program.cs
│ │ └── Properties
│ │ └── launchSettings.json
│ ├── PhotoFrame.Logic
│ │ ├── AppModel.cs
│ │ ├── BL
│ │ │ ├── FrameController.cs
│ │ │ ├── IFrameController.cs
│ │ │ ├── PhotoDatabase.cs
│ │ │ ├── ViewSwitchType.cs
│ │ │ └── ViewType.cs
│ │ ├── Config
│ │ │ ├── FrameJsonConfig.cs
│ │ │ └── IFrameConfig.cs
│ │ ├── IAppModel.cs
│ │ ├── PhotoFrameConfig.json
│ │ ├── PhotoFrame.Logic.csproj
│ │ ├── UI
│ │ │ ├── images
│ │ │ │ ├── abandoned-forest-industry-34950.jpg
│ │ │ │ ├── agriculture-apple-blur-257840.jpg
│ │ │ │ ├── animal-animal-photography-big-cat-145939.jpg
│ │ │ │ ├── art-ball-ball-shaped-235615.jpg
│ │ │ │ ├── beautiful-bird-s-eye-view-boats-1039302.jpg
│ │ │ │ ├── clouds-cloudy-countryside-236047.jpg
│ │ │ │ └── mobilechallenge-4k-wallpaper-close-up-807598.jpg
│ │ │ ├── QML
│ │ │ │ ├── main.qml
│ │ │ │ ├── ViewBorder.qml
│ │ │ │ ├── ViewColorized.qml
│ │ │ │ └── ViewNormal.qml
│ │ │ ├── ViewModels
│ │ │ │ ├── IViewModel.cs
│ │ │ │ ├── ViewModelBase.cs
│ │ │ │ ├── ViewModelBorder.cs
│ │ │ │ ├── ViewModelColorize.cs
│ │ │ │ ├── ViewModelNormal.cs
│ │ │ │ └── ViewSwitchInfo.cs
│ │ │ └── Views
│ │ │ ├── IView.cs
│ │ │ ├── IViewManager.cs
│ │ │ ├── ViewBase.cs
│ │ │ ├── ViewBorder.cs
│ │ │ ├── ViewColorize.cs
│ │ │ ├── ViewManager.cs
│ │ │ └── ViewNormal.cs
│ │ ├── UIDispatchDelegate.cs
│ │ └── Utils.cs
│ ├── PhotoFrame.Logic.Tests
│ │ ├── BL
│ │ │ ├── PhotoDatabaseTest.cs
│ │ │ └── testphotos
│ │ │ ├── abandoned-forest-industry-34950.jpg
│ │ │ ├── agriculture-apple-blur-257840.jpg
│ │ │ ├── animal-animal-photography-big-cat-145939.jpg
│ │ │ ├── art-ball-ball-shaped-235615.jpg
│ │ │ └── beautiful-bird-s-eye-view-boats-1039302.jpg
│ │ ├── PhotoFrame.Logic.Tests.csproj
│ │ └── UI
│ │ ├── ViewModels
│ │ │ ├── ViewModelBaseTest.cs
│ │ │ ├── ViewModelBorderTest.cs
│ │ │ ├── ViewModelColorizeTest.cs
│ │ │ ├── ViewModelNormalTest.cs
│ │ │ ├── ViewModelTestBase.cs
│ │ │ └── ViewSwitchInfoTest.cs
│ │ └── Views
│ │ ├── ViewBaseTest.cs
│ │ ├── ViewBorderTest.cs
│ │ ├── ViewColorizeTest.cs
│ │ ├── ViewManagerTest.cs
│ │ ├── ViewNormalTest.cs
│ │ └── ViewTestBase.cs
│ ├── PhotoFrame.sln
│ └── Readme.md
├── src
│ ├── native
│ │ ├── build.bat
│ │ ├── build.sh
│ │ ├── QmlNet
│ │ ├── Qml.Net.LinuxBinaries.csproj
│ │ ├── Qml.Net.OSXBinaries.csproj
│ │ └── Qml.Net.WindowsBinaries.csproj
│ └── net
│ ├── Directory.Build.props
│ ├── Qml.Net
│ │ ├── ApplicationAttribute.cs
│ │ ├── BaseDisposable.cs
│ │ ├── Extensions
│ │ │ └── INetJsValueExtensions.cs
│ │ ├── Host.cs
│ │ ├── INetJsValue.cs
│ │ ├── INetQObject.cs
│ │ ├── Internal
│ │ │ ├── Behaviors
│ │ │ │ ├── AutoGenerateNotifySignalsBehavior.cs
│ │ │ │ └── MvvmQmlInteropBehavior.cs
│ │ │ ├── CodeGen
│ │ │ │ ├── CodeGen.cs
│ │ │ │ └── CodeGen.Methods.cs
│ │ │ ├── Converter.cs
│ │ │ ├── DefaultCallbacks.cs
│ │ │ ├── Del.cs
│ │ │ ├── Helpers.cs
│ │ │ ├── InteropBehaviors.cs
│ │ │ ├── Interop.cs
│ │ │ ├── IQmlInteropBehavior.cs
│ │ │ ├── LinuxDllImportLibraryPathResolver.cs
│ │ │ ├── MacDllImportLibraryPathResolver.cs
│ │ │ ├── NativeSymbolAttribute.cs
│ │ │ ├── ObjectSignals.cs
│ │ │ ├── ObjectTagger.cs
│ │ │ ├── Qml
│ │ │ │ ├── NetJsValue.cs
│ │ │ │ ├── NetQObject.cs
│ │ │ │ ├── NetQObjectSignalConnection.cs
│ │ │ │ ├── NetTestHelper.cs
│ │ │ │ ├── NetVariant.cs
│ │ │ │ └── NetVariantList.cs
│ │ │ ├── Types
│ │ │ │ ├── Callbacks.cs
│ │ │ │ ├── NetDelegate.cs
│ │ │ │ ├── NetMethodInfo.cs
│ │ │ │ ├── NetPropertyInfo.cs
│ │ │ │ ├── NetReference.cs
│ │ │ │ ├── NetSignalInfo.cs
│ │ │ │ ├── NetTypeInfo.cs
│ │ │ │ └── NetTypeManager.cs
│ │ │ └── WindowsDllImportLibraryPathResolver.cs
│ │ ├── IQmlComponentCompleted.cs
│ │ ├── IQmlObjectDestroyed.cs
│ │ ├── NetQPainter.cs
│ │ ├── NetVariantType.cs
│ │ ├── NotifySignalAttribute.cs
│ │ ├── Properties.cs
│ │ ├── QApplication.cs
│ │ ├── QCoreApplication.cs
│ │ ├── QEventLoop.cs
│ │ ├── QGuiApplication.cs
│ │ ├── QLocale.cs
│ │ ├── Qml.cs
│ │ ├── QmlNetConfig.cs
│ │ ├── Qml.Net.csproj
│ │ ├── QmlNetQuickPaintedItem.cs
│ │ ├── QQmlApplicationEngine.cs
│ │ ├── QQuickStyle.cs
│ │ ├── QResource.cs
│ │ ├── Qt.cs
│ │ ├── QTest.cs
│ │ ├── QtWebEngine.cs
│ │ ├── Runtimes
│ │ │ ├── Chmod.cs
│ │ │ ├── RuntimeArchitecture.cs
│ │ │ ├── RuntimeManager.Configure.cs
│ │ │ ├── RuntimeManager.cs
│ │ │ ├── RuntimeManager.Discovery.cs
│ │ │ ├── Symlink.cs
│ │ │ └── Tar.cs
│ │ ├── Serialization
│ │ │ ├── ISerializer.cs
│ │ │ └── NewtonSerializer.cs
│ │ ├── Serializer.cs
│ │ ├── SignalAttribute.cs
│ │ ├── Signals.cs
│ │ ├── TypeCreator.cs
│ │ └── Utilities.cs
│ ├── Qml.Net.Benchmarks
│ │ ├── Config.cs
│ │ ├── Program.cs
│ │ ├── Qml.Net.Benchmarks.csproj
│ │ └── QObjectMethodBenchmarks.cs
│ ├── Qml.Net.Sandbox
│ │ ├── Images
│ │ │ └── placeholder.png
│ │ ├── main.qml
│ │ ├── Program.Tests.cs
│ │ ├── Program.UI.cs
│ │ ├── Qml
│ │ │ └── MyModule
│ │ │ ├── factorial.js
│ │ │ ├── factorial.jsc
│ │ │ └── qmldir
│ │ └── Qml.Net.Sandbox.csproj
│ ├── Qml.Net.sln
│ ├── Qml.Net.sln.DotSettings
│ ├── Qml.Net.Tests
│ │ ├── BaseRuntimeManagerTests.cs
│ │ ├── BaseTests.cs
│ │ ├── CodeGen
│ │ │ ├── CodeGenBase.cs
│ │ │ ├── CodeGenParameterTests.cs
│ │ │ ├── CodeGenPropertyTests.cs
│ │ │ ├── CodeGenReturnTypeTests.cs
│ │ │ └── CodeGenStructTests.cs
│ │ ├── Internal
│ │ │ └── ObjectTaggerTests.cs
│ │ ├── MockTypeCreator.cs
│ │ ├── Properties.cs
│ │ ├── Qml
│ │ │ ├── AutoSignalTests.cs
│ │ │ ├── AwaitTests.cs
│ │ │ ├── BaseQmlTests.cs
│ │ │ ├── BoolTests.cs
│ │ │ ├── ByteArrayTests.cs
│ │ │ ├── CharTests.cs
│ │ │ ├── ColorTests.cs
│ │ │ ├── CommonTests.cs
│ │ │ ├── DateTimeOffsetTests.cs
│ │ │ ├── DateTimeTests.cs
│ │ │ ├── DoubleTests.cs
│ │ │ ├── EnumTests.cs
│ │ │ ├── IntTests.cs
│ │ │ ├── JsValueTests.cs
│ │ │ ├── LifetimeTests.cs
│ │ │ ├── ListModelTests.cs
│ │ │ ├── Matrix4x4Tests.cs
│ │ │ ├── MethodTests.cs
│ │ │ ├── MvvmInteropBehaviorTests.cs
│ │ │ ├── NetVariantTests.cs
│ │ │ ├── ObjectTests.cs
│ │ │ ├── PointFTests.cs
│ │ │ ├── PointTests.cs
│ │ │ ├── PropertyTests.cs
│ │ │ ├── QmlNetQuickPaintedItemTests.cs
│ │ │ ├── QObjectTests.cs
│ │ │ ├── QQmlApplicationEngineTests.cs
│ │ │ ├── QTestTests.cs
│ │ │ ├── QuaternionTests.cs
│ │ │ ├── RectFTests.cs
│ │ │ ├── RectTests.cs
│ │ │ ├── SerializationTests.cs
│ │ │ ├── SignalTests.cs
│ │ │ ├── SingletonTests.cs
│ │ │ ├── SizeFTests.cs
│ │ │ ├── SizeTests.cs
│ │ │ ├── StringTests.cs
│ │ │ ├── UIntTests.cs
│ │ │ ├── UrlTests.cs
│ │ │ ├── Vector2Tests.cs
│ │ │ ├── Vector3Tests.cs
│ │ │ └── Vector4Tests.cs
│ │ ├── Qml.Net.Tests.csproj
│ │ ├── RuntimeManagerDiscoveryTests.cs
│ │ ├── RuntimeManagerTests.cs
│ │ └── Types
│ │ ├── CallbacksTests.cs
│ │ ├── NetDelegateTests.cs
│ │ ├── NetReferenceTests.cs
│ │ ├── NetSignalInfoTests.cs
│ │ ├── NetTypeInfoTests.cs
│ │ ├── NetTypeManagerTests.cs
│ │ └── NetVariantListTests.cs
│ └── styles.ruleset
└── tmp
└── Test
├── main.cpp
├── main.qml
├── Page1Form.ui.qml
├── Page1.qml
├── qml.qrc
├── qtquickcontrols2.conf
└── Test.pro
52 directories, 257 files
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论