[GH-ISSUE #15] Support for accessing embedded .NET resources within Qml. #12

Open
opened 2026-05-05 10:59:03 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @pauldotknopf on GitHub (Jul 18, 2018).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/15

https://wiki.qt.io/QtResources

We'd have to pinvoke the data into a special C struct that Qt can use to register it as a resource that can be loaded in Qml (whether it's other Qml files, or images, etc).

Originally created by @pauldotknopf on GitHub (Jul 18, 2018). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/15 https://wiki.qt.io/QtResources We'd have to pinvoke the data into a special C struct that Qt can use to register it as a resource that can be loaded in Qml (whether it's other Qml files, or images, etc).
Author
Owner

@pauldotknopf commented on GitHub (Jul 18, 2018):

Here is how to get a raw pointer to the embedded resource for usage in Qt: https://stackoverflow.com/questions/51406733/net-embedded-resource-getting-an-intptr-to-the-raw-memory-location-for-use-in/51407990#51407990

<!-- gh-comment-id:406015689 --> @pauldotknopf commented on GitHub (Jul 18, 2018): Here is how to get a raw pointer to the embedded resource for usage in Qt: https://stackoverflow.com/questions/51406733/net-embedded-resource-getting-an-intptr-to-the-raw-memory-location-for-use-in/51407990#51407990
Author
Owner

@shartte commented on GitHub (Apr 13, 2020):

While true, having to copy the resource data in-memory and keep it around (because it needs to be in the RCC format apparently) seems wasteful.
Here's what I'll actually attempt for my project:

  • Somehow integrate RCC as a MSBuild task
  • Embed the resulting .rcc file into the .NET DLL
  • PInvoke QResource::registerResource with the raw data (which was produced by RCC and is embedded in the .NET DLL)
<!-- gh-comment-id:613034412 --> @shartte commented on GitHub (Apr 13, 2020): While true, having to copy the resource data in-memory and keep it around (because it needs to be in the RCC format apparently) seems wasteful. Here's what I'll actually attempt for my project: - Somehow integrate RCC as a MSBuild task - Embed the resulting .rcc file into the .NET DLL - PInvoke QResource::registerResource with the raw data (which was produced by RCC and is embedded in the .NET DLL)
Author
Owner

@pauldotknopf commented on GitHub (Apr 13, 2020):

The pointer to the embedded resource is a static non-changing pointer. I believe it's in memory at all times, the moment the .NET dll is loaded.

I do like your idea though, the more we can set on top of traditional/supported APIs, the better, and manually building that struct sounds problematic.

<!-- gh-comment-id:613082211 --> @pauldotknopf commented on GitHub (Apr 13, 2020): The pointer to the embedded resource is a static non-changing pointer. I believe it's in memory at all times, the moment the .NET dll is loaded. I do like your idea though, the more we can set on top of traditional/supported APIs, the better, and manually building that struct sounds problematic.
Author
Owner

@shartte commented on GitHub (Apr 13, 2020):

The challenge of making this developer-friendly will most likely be providing a NuGet package that has:

  • The required MSBuild targets (I think this is already nicely supported in the .NET Core/.csproj world, but not sure about traditional .NET framework)
  • A prefferrably statically built rcc.exe for the major platforms (Linux, Mac, Windows). 32 vs 64-bit might not matter, since it's never packaged with the app itself
  • Care must be taken to build it with ZStd compression support (this is not trivial to do on Windows)

I might look into this soon.

<!-- gh-comment-id:613114366 --> @shartte commented on GitHub (Apr 13, 2020): The challenge of making this developer-friendly will most likely be providing a NuGet package that has: - The required MSBuild targets (I think this is already nicely supported in the .NET Core/.csproj world, but not sure about traditional .NET framework) - A prefferrably statically built rcc.exe for the major platforms (Linux, Mac, Windows). 32 vs 64-bit might not matter, since it's never packaged with the app itself - Care must be taken to build it with ZStd compression support (this is not trivial to do on Windows) I might look into this soon.
Author
Owner

@pauldotknopf commented on GitHub (Apr 13, 2020):

Are you using unmanaged hosting or unmanaged hosting?

<!-- gh-comment-id:613133326 --> @pauldotknopf commented on GitHub (Apr 13, 2020): Are you using unmanaged hosting or unmanaged hosting?
Author
Owner

@shartte commented on GitHub (Apr 14, 2020):

I am using managed hosting with some extra custom native glue.

<!-- gh-comment-id:613483378 --> @shartte commented on GitHub (Apr 14, 2020): I am using managed hosting with some extra custom native glue.
Author
Owner

@vadi2 commented on GitHub (May 10, 2021):

@shartte did you get this working? Would like to embed resources for quicker startup performance.

<!-- gh-comment-id:836561338 --> @vadi2 commented on GitHub (May 10, 2021): @shartte did you get this working? Would like to embed resources for quicker startup performance.
Author
Owner

@shartte commented on GitHub (May 10, 2021):

I don't think I actually completed this. I had to go back and search and couldn't find it :-(

The general idea however should still be sound. But writing MSBuild tasks is certainly not "fun".

<!-- gh-comment-id:836574024 --> @shartte commented on GitHub (May 10, 2021): I don't think I actually completed this. I had to go back and search and couldn't find it :-( The general idea however should still be sound. But writing MSBuild tasks is certainly not "fun".
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#12
No description provided.