[GH-ISSUE #171] Cannot use already existing installation of QT 5.10.1 #109

Closed
opened 2026-05-05 11:05:12 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @bairog on GitHub (Oct 30, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/171

Hello.

On thet Requirements page we can see Qt 5.10+. So I've expected to be able to use QML .NET with already existing installation of QT.

I'm on Windows 10 1903 x64. I've installed QT 5.10.1 prebuilt components for MSVC 2017 64-bit via qt-opensource-windows-x86-5.10.1.exe.
Resulting installation folder is C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64 (during installation process I was able to choose only C:\Qt\Qt_5.10.1 folder - all subfolders are selected automatically).
And of course that resulting folder contains all necessary subfolders - bin, plugins and qml.

I'm trying to run QML .Net example using my existing installation:
RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\")

But that results in error that

Plugins directory didn't exist "CC:\Qt\Qt_5.10.1\5.10.1\qt\plugins"

Looks like qt subfolder name is hardcoded inside RuntimeManager.Configure.cs

So how to deal with that situation?
How to properly use QML .NET with already existing installation of QT 5.10.1 (editing RuntimeManager.Configure.cs and recompile QML.Net.dll is not a good option)?

Thank you.

Originally created by @bairog on GitHub (Oct 30, 2019). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/171 Hello. On thet [Requirements](https://qmlnet.github.io/introduction/requirements/) page we can see **Qt 5.10+**. So I've expected to be able to use QML .NET with already existing installation of QT. I'm on Windows 10 1903 x64. I've installed QT 5.10.1 prebuilt components for **MSVC 2017 64-bit** via [qt-opensource-windows-x86-5.10.1.exe](https://download.qt.io/archive/qt/5.10/5.10.1/qt-opensource-windows-x86-5.10.1.exe). Resulting installation folder is **C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64** (during installation process I was able to choose only **C:\Qt\Qt_5.10.1** folder - all subfolders are selected automatically). And of course that resulting folder contains all necessary subfolders - **bin**, **plugins** and **qml**. I'm trying to run QML .Net example using my existing installation: `RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\")` But that results in error that > Plugins directory didn't exist "CC:\Qt\Qt_5.10.1\5.10.1\qt\plugins" Looks like **qt** subfolder name is hardcoded inside [RuntimeManager.Configure.cs](https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net/Runtimes/RuntimeManager.Configure.cs) So how to deal with that situation? How to properly use QML .NET with already existing installation of QT 5.10.1 (editing RuntimeManager.Configure.cs and recompile QML.Net.dll is not a good option)? Thank you.
Author
Owner

@pauldotknopf commented on GitHub (Oct 30, 2019):

Hmm, it looks like that RuntimeManager.Configure needs to poke around a bit more.

The only thing that method does though is set some environment variables. You could set those yourself in Program.Main. Really though, in production environments, this is how it should be done, considering most published applications embed the Qt framework privately in their own folder.

<!-- gh-comment-id:547870156 --> @pauldotknopf commented on GitHub (Oct 30, 2019): Hmm, it looks like that ```RuntimeManager.Configure``` needs to poke around a bit more. The only thing that method does though is set some environment variables. You could set those yourself in ```Program.Main```. Really though, in production environments, this is how it should be done, considering most published applications embed the Qt framework privately in their own folder.
Author
Owner

@pauldotknopf commented on GitHub (Oct 30, 2019):

Also, if you use your own Qt runtime, make sure you compile the native bits for Qml.Net yourself and put them in your PATH somewhere.

<!-- gh-comment-id:547870431 --> @pauldotknopf commented on GitHub (Oct 30, 2019): Also, if you use your own Qt runtime, make sure you compile the native bits for Qml.Net yourself and put them in your PATH somewhere.
Author
Owner

@bairog commented on GitHub (Oct 30, 2019):

make sure you compile the native bits for Qml.Net yourself and put them in your PATH somewhere.

Oh, could you clarify this more, please. Maybe some documentation about this case.

<!-- gh-comment-id:547893683 --> @bairog commented on GitHub (Oct 30, 2019): > make sure you compile the native bits for Qml.Net yourself and put them in your PATH somewhere. Oh, could you clarify this more, please. Maybe some documentation about this case.
Author
Owner

@pauldotknopf commented on GitHub (Oct 30, 2019):

Allow me to clarify.

All Qt libs (when using private headers) must be compiled against the exact Qt version they are running against. So, you can't just use "Qml.Net.WindowsBinaries" with any Qt runtime. If you use your own Qt installation, you must only use the Qml.Net package, and compile the native libs that are in "Qml.Net.WindowsBinaries" yourself.

The build/installation is really simple. See here.

The "Qml.Net" package will find an invoke the native C-interop QmlNet.dll properly.

<!-- gh-comment-id:547896632 --> @pauldotknopf commented on GitHub (Oct 30, 2019): Allow me to clarify. All Qt libs (when using private headers) must be compiled against the exact Qt version they are running against. So, you can't just use "Qml.Net.WindowsBinaries" with any Qt runtime. If you use your own Qt installation, you must only use the Qml.Net package, and compile the native libs that are in "Qml.Net.WindowsBinaries" yourself. The build/installation is really simple. See [here](https://github.com/qmlnet/qmlnet/blob/develop/src/native/build.bat). The "Qml.Net" package will find an invoke the native C-interop QmlNet.dll properly.
Author
Owner

@bairog commented on GitHub (Oct 31, 2019):

What I've tried (on Windows 10 1903 x64):

  1. Installed QT 5.10.1 prebuilt components for MSVC 2017 64-bit via qt-opensource-windows-x86-5.10.1.exe. Resulting installation folder is C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64.
  2. Downloaded qmlnet repository. Inside build.bat i've changed qmake to C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64\bin\qmake and jom to C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64\Tools\QtCreator\bin\jom.
  3. Started Visual Studio 2019 Developer Command Prompt v16.3.6 and started build.bat inside it. Succesfully built native C-interop library - \output\QmlNet.dll.
  4. Downloaded qmlnet-examples repository. Removed Nuget references to all runtimes (MacOSX, Linux and Windows). Copied QmlNet.dll to project folder.
  5. Added RuntimeManager.Configure.cs to qmlnet-examples project (inside that file I've changed namespace to Features and changed hardcoded qt subdirectory name to msvc2017_64). Inside Program.Main I've changed RuntimeManager.DiscoverOrDownloadSuitableQtRuntimes(); to RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\");.
  6. Compiled qmlnet-examples project (restored all needed Nuget packages of course) and started debugging.
  7. RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\"); finished correctly. But QQuickStyle.SetStyle("Material"); results in exception:

System.TypeInitializationException: The type initializer for 'Qml.Net.Internal.Interop' threw an exception (inside Qml.Net)
System.Exception: Symbol loading failed. Symbol name: type_info_setPrefVariantType (inside NetNativeLibLoader)

So what I am doing wrong?

<!-- gh-comment-id:548277359 --> @bairog commented on GitHub (Oct 31, 2019): What I've tried (on Windows 10 1903 x64): 0. Installed **QT 5.10.1** prebuilt components for **MSVC 2017 64-bit** via [qt-opensource-windows-x86-5.10.1.exe](https://download.qt.io/archive/qt/5.10/5.10.1/qt-opensource-windows-x86-5.10.1.exe). Resulting installation folder is **C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64**. 1. Downloaded [qmlnet](https://github.com/qmlnet/qmlnet) repository. Inside [build.bat](https://github.com/qmlnet/qmlnet/blob/develop/src/native/build.bat) i've changed qmake to **C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64\bin\qmake** and jom to **C:\Qt\Qt_5.10.1\5.10.1\msvc2017_64\Tools\QtCreator\bin\jom**. 2. Started **Visual Studio 2019 Developer Command Prompt v16.3.6** and started build.bat inside it. Succesfully built native C-interop library - **\output\QmlNet.dll**. 3. Downloaded [qmlnet-examples](https://github.com/qmlnet/qmlnet-examples) repository. Removed Nuget references to all runtimes (MacOSX, Linux and Windows). Copied **QmlNet.dll** to project folder. 4. Added [RuntimeManager.Configure.cs](https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net/Runtimes/RuntimeManager.Configure.cs) to **qmlnet-examples** project (inside that file I've changed namespace to **Features** and changed hardcoded **qt** subdirectory name to **msvc2017_64**). Inside **Program.Main** I've changed `RuntimeManager.DiscoverOrDownloadSuitableQtRuntimes();` to `RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\");`. 5. Compiled **qmlnet-examples** project (restored all needed Nuget packages of course) and started debugging. 6. `RuntimeManager.ConfigureRuntimeDirectory(@"C:\Qt\Qt_5.10.1\5.10.1\");` finished correctly. But `QQuickStyle.SetStyle("Material");` results in exception: > System.TypeInitializationException: The type initializer for 'Qml.Net.Internal.Interop' threw an exception (inside Qml.Net) > System.Exception: Symbol loading failed. Symbol name: type_info_setPrefVariantType (inside NetNativeLibLoader) So what I am doing wrong?
Author
Owner

@bairog commented on GitHub (Oct 31, 2019):

I've tried the same approach with Qt 5.11.0 on Debian 9-based Linux distrib.
On Step 2 I've succesfully compiled \output\libQmlNet.so via build.sh.
But again on Step 6 I've faced the same exceptions.
Looks like I'm going the wrong way :)

<!-- gh-comment-id:548343945 --> @bairog commented on GitHub (Oct 31, 2019): I've tried the same approach with **Qt 5.11.0** on **Debian 9**-based Linux distrib. On **Step 2** I've succesfully compiled **\output\libQmlNet.so** via **build.sh**. But again on **Step 6** I've faced the same exceptions. Looks like I'm going the wrong way :)
Author
Owner

@pauldotknopf commented on GitHub (Nov 3, 2019):

Make sure you compile the native lib using the same exact version as the NuGet library. Checkout the write tag in the git repo.

<!-- gh-comment-id:549109569 --> @pauldotknopf commented on GitHub (Nov 3, 2019): Make sure you compile the native lib using the same exact version as the NuGet library. Checkout the write tag in the git repo.
Author
Owner

@bairog commented on GitHub (Nov 5, 2019):

Oh, that was my mistake. I used latest version of native lib instead of release 0.10.1. Now it's working (both Windows and Linux).

Final instruction for using Qml .Net with existing QT installation (tested on Windows 10 1903 x64 with QT 5.10.1 and Debian 9 with QT 5.11.0):

  1. Download qmlnet repository for the same exact version as the NuGet library.
  2. On Windows: Inside build.bat change qmake to Your_QT_bin_path\qmake and jom to Your_QtCreator_bin_path\jom. Start Visual Studio 2019 Developer Command Prompt v16.3.6 x64 and run build.bat inside it.
    On Linux: Simply run build.sh.
  3. On both systems Native C-interop library will be built to \output folder. Copy that library to your project folder.
  4. Use code from RuntimeManager.Configure.cs directly in your project. Make sure that inside RuntimeManager.ConfigureRuntimeDirectory() you've changed hardcoded qt subdirectory name to msvc2017_64 or the one that you use.
  5. Use RuntimeManager.ConfigureRuntimeDirectory(Your_QT_directory); instead of RuntimeManager.DiscoverOrDownloadSuitableQtRuntimes();
  6. Now your code doesn't need to download Qml .Net precompiled QT runtimes and can run on your existing QT installation.
<!-- gh-comment-id:549674938 --> @bairog commented on GitHub (Nov 5, 2019): Oh, that was my mistake. I used latest version of native lib instead of **release 0.10.1**. Now it's working (both Windows and Linux). Final instruction for using Qml .Net with existing QT installation (tested on **Windows 10 1903 x64** with **QT 5.10.1** and **Debian 9** with **QT 5.11.0**): 1. Download [qmlnet](https://github.com/qmlnet/qmlnet/releases) repository for **the same exact version as the NuGet library**. 2. On Windows: Inside [build.bat](https://github.com/qmlnet/qmlnet/blob/develop/src/native/build.bat) change qmake to **Your_QT_bin_path\qmake** and jom to **Your_QtCreator_bin_path\jom**. Start **Visual Studio 2019 Developer Command Prompt v16.3.6 x64** and run build.bat inside it. On Linux: Simply run build.sh. 3. On both systems Native C-interop library will be built to **\output** folder. Copy that library to your project folder. 4. Use code from [RuntimeManager.Configure.cs](https://github.com/qmlnet/qmlnet/blob/develop/src/net/Qml.Net/Runtimes/RuntimeManager.Configure.cs) directly in your project. Make sure that inside `RuntimeManager.ConfigureRuntimeDirectory()` you've changed hardcoded **qt** subdirectory name to **msvc2017_64** or the one that you use. 5. Use `RuntimeManager.ConfigureRuntimeDirectory(Your_QT_directory);` instead of `RuntimeManager.DiscoverOrDownloadSuitableQtRuntimes();` 6. Now your code doesn't need to download Qml .Net precompiled QT runtimes and can run on your existing QT installation.
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#109
No description provided.