[GH-ISSUE #197] Can't build latest QmlNet with Qt 5.14.2 on Windows #128

Closed
opened 2026-05-05 11:06:01 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @BrianAllred on GitHub (Apr 29, 2020).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/197

Repo is here.

PATH is set to C:\Qt\5.14.2\mingw73_64\bin;C:\Qt\Tools\mingw730_64\bin;%PATH%

Build script:

git submodule sync --recursive
git submodule update --init --recursive

mkdir .\bin\release
cd .\bin\release

dotnet restore ..\..\net\
dotnet build -c Release -o .\ ..\..\net\
qmake ..\..\QmlYodel.pro CONFIG+=release DESTDIR=%cd%
mingw32-make

image

Originally created by @BrianAllred on GitHub (Apr 29, 2020). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/197 Repo is [here](https://gitlab.com/BrianAllred/qml-yodel). PATH is set to `C:\Qt\5.14.2\mingw73_64\bin;C:\Qt\Tools\mingw730_64\bin;%PATH%` Build script: ``` git submodule sync --recursive git submodule update --init --recursive mkdir .\bin\release cd .\bin\release dotnet restore ..\..\net\ dotnet build -c Release -o .\ ..\..\net\ qmake ..\..\QmlYodel.pro CONFIG+=release DESTDIR=%cd% mingw32-make ``` ![image](https://user-images.githubusercontent.com/5847511/80651628-d76a6880-8a3b-11ea-8ebb-79106a42d338.png)
Author
Owner

@pauldotknopf commented on GitHub (May 10, 2020):

I'm sorry for the delay here. When I find time to get my Windows box up and running, I'll check it out.

However, it looks to be a simple #define mix-up and the latest Qt bits. Maybe you could take a stab at it?

<!-- gh-comment-id:626304332 --> @pauldotknopf commented on GitHub (May 10, 2020): I'm sorry for the delay here. When I find time to get my Windows box up and running, I'll check it out. However, it looks to be a simple ```#define``` mix-up and the latest Qt bits. Maybe you could take a stab at it?
Author
Owner

@BrianAllred commented on GitHub (May 12, 2020):

I downgraded to Qt 5.12.2 using MSVC++ 2017 and still get the same issue. Tried it with a brand new VM and project just to verify it wasn't an environment issue.

I'll take a look when I have time, but my C++ is pretty rusty.

<!-- gh-comment-id:627578024 --> @BrianAllred commented on GitHub (May 12, 2020): I downgraded to Qt 5.12.2 using MSVC++ 2017 and still get the same issue. Tried it with a brand new VM and project just to verify it wasn't an environment issue. I'll take a look when I have time, but my C++ is pretty rusty.
Author
Owner

@BrianAllred commented on GitHub (May 16, 2020):

After a little bit of investigation, the attached diff fixed the build. I haven't had time to see if it actually runs correctly yet. I'll update when I do.

diff --git a/src/native/QmlNet/Hosting/CoreHost.cpp b/src/native/QmlNet/Hosting/CoreHost.cpp
index d3029ce..882a023 100644
--- a/src/native/QmlNet/Hosting/CoreHost.cpp
+++ b/src/native/QmlNet/Hosting/CoreHost.cpp
@@ -22,8 +22,18 @@ static QString nativeModule;
 
 static void* getExportedFunction(const char* symbolName) {
 #ifdef _WIN32
+#ifdef UNICODE
+    wchar_t *array = new wchar_t[nativeModule.length() + 1];
+    nativeModule.toWCharArray(array);
+    array[nativeModule.length()] = 0;
+
+    HMODULE library = GetModuleHandle(nativeModule.isNull() || nativeModule.isEmpty() ? nullptr
+                                                                                      : array);
+#else
     HMODULE library = GetModuleHandle(nativeModule.isNull() || nativeModule.isEmpty() ? nullptr
-                                                                                     : nativeModule.toLocal8Bit());
+                                                                                      : nativeModule.toLocal8Bit());
+#endif
+
     FARPROC symbol = GetProcAddress(library, symbolName);
     return (void*)symbol;
 #else

<!-- gh-comment-id:629701171 --> @BrianAllred commented on GitHub (May 16, 2020): After a little bit of investigation, the attached diff fixed the build. I haven't had time to see if it actually runs correctly yet. I'll update when I do. ``` diff --git a/src/native/QmlNet/Hosting/CoreHost.cpp b/src/native/QmlNet/Hosting/CoreHost.cpp index d3029ce..882a023 100644 --- a/src/native/QmlNet/Hosting/CoreHost.cpp +++ b/src/native/QmlNet/Hosting/CoreHost.cpp @@ -22,8 +22,18 @@ static QString nativeModule; static void* getExportedFunction(const char* symbolName) { #ifdef _WIN32 +#ifdef UNICODE + wchar_t *array = new wchar_t[nativeModule.length() + 1]; + nativeModule.toWCharArray(array); + array[nativeModule.length()] = 0; + + HMODULE library = GetModuleHandle(nativeModule.isNull() || nativeModule.isEmpty() ? nullptr + : array); +#else HMODULE library = GetModuleHandle(nativeModule.isNull() || nativeModule.isEmpty() ? nullptr - : nativeModule.toLocal8Bit()); + : nativeModule.toLocal8Bit()); +#endif + FARPROC symbol = GetProcAddress(library, symbolName); return (void*)symbol; #else ```
Author
Owner

@BrianAllred commented on GitHub (May 17, 2020):

Nope. With the above patch, Qt complains at runtime about not being able to find registered .NET types.

<!-- gh-comment-id:629732586 --> @BrianAllred commented on GitHub (May 17, 2020): Nope. With the above patch, Qt complains at runtime about not being able to find registered .NET types.
Author
Owner

@shartte commented on GitHub (May 29, 2020):

The root cause here seems to be compiling with _UNICODE defined, which I'd say is usually recommended.
You could try without it though.

<!-- gh-comment-id:636187554 --> @shartte commented on GitHub (May 29, 2020): The root cause here seems to be compiling with _UNICODE defined, which I'd say is usually recommended. You could try without it though.
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#128
No description provided.