KDAB / cxx-qt

Safe interop between Rust and Qt
https://kdab.github.io/cxx-qt/book/
1.02k stars 68 forks source link

Windows WSL2 WSLg not rendering inside window and release only build #682

Open AddictArts opened 1 year ago

AddictArts commented 1 year ago

Windows 11 x64

Passing along feedback that like other people have reported release only builds are needed on the Windows 11 side. The default or debug does not complete and create an executable. The below worked for me. The cargo only build did not work either, could not find Qt stuff. Error was QtMissing ... See also #498 and #676

cmake --build build --config Release

WSL2 WSLg Ubuntu 22

The cmake build works and the cargo only. However, it does not render anything in the window, just a white canvas, no buttons, etc controls. The button is clickable and I see terminal output, "Hi from rust ...". Unfortunately the empty window has no workaround that I could find. I don't know if this is a Qt issue and WSLg.

Last issue Qt organization, if you download from them you are forced to use Qt6.5 and this project is not ready for that. This is unfortunate and not a good developer experience. Don't understand the poor support for prior releases. This is not anyone's here fault, just noting the latest may cause issues.

ahayzen-kdab commented 1 year ago

Thanks for taking the time to report the issue.

I would be interested if someone could point to where the debug vs release build is going wrong on Windows. As a lot of this is coming from Corrosion now. Is this the issue with the "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDLL" that needs to be set ? Or is this another issue ? (and we have some fun of where to put that, eg in the root CMakeList for when people are building the repository or in each of the examples CMakeLists?).

I don't think any of us have tried this on WSLg, not many of us have even tried it on Windows.

From the Qt online installer you should be able to download any release you want via the "archive" checkbox on the right side then click "filter" (eg i can pick any version from 5.9 -> 6.6 beta).

ahayzen-kdab commented 1 year ago

Wonder if we are hitting the difference between CMAKE_BUILD_TYPE=Debug that we set in the CMakeList and --config Debug, appears that different generators might do different things there? We could try removing those lines tomorrow and see what happens...

AddictArts commented 1 year ago

Thanks @ahayzen-kdab

Maybe I have this wrong, I set $Env:CMAKE_MSVC_RUNTIME_LIBRARY = "MultiThreadedDLL" Did not help and same error

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

For debug build

Added line 173

    )
+
+   set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")

    list(

This produced the debug build with only the LINK warning.

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
AddictArts commented 1 year ago

I’m thinking the WSL2 WSLg issue is due to theme. Other Qt apps render fine. One assistant reports the theme is not set.

ahayzen-kdab commented 1 year ago

I see how we are hitting

https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets

and

https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-rust-static-libraries-into-debug-cc-binaries-fails-on-windows-msvc-targets

These are issues that @OlivierLDff was also trying to solve. I wonder if we can set the right things in the CMakeLists for now to make things happy.

Eg do we set set_target_properties(target PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") and / or corrosion_set_env_vars(corrosion-crate "CFLAGS=-MDd" "CXXFLAGS=-MDd") to all our targets in CMake. So that folks can find this when following the book and it's not just hidden in the global CMakeList / preset.

I also wonder if we can get away with one of them and if they work for both Debug and Release builds or whether there is more fine tuning to do there...

ahayzen-kdab commented 1 year ago

Or maybe we just set in all our CMake files so it happens everywhere and easy for folks to see in the examples :shrug:

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
ahayzen-kdab commented 1 year ago

Would be interesting if #683 makes things better or worse :-)

OlivierLDff commented 1 year ago

Or maybe we just set in all our CMake files so it happens everywhere and easy for folks to see in the examples 🤷

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()

This is the "best" way to handle it that will break less stuff that #683

ahayzen-kdab commented 1 year ago

683 should solve the _ITERATOR_DEBUG_LEVEL issue :-)

ahayzen-kdab commented 1 year ago

After ensuring that the folder that contains qmake.exe is in PATH and using #683.

I can run (using msvc2019 + Qt online installer 5.15.2) CMake builds and targets from QtCreator and I can run cargo run -p qml-minimal-no-cmake and it also shows a window correctly.

So the remaining issue on this task is whether something specific to WSL2 / WSLg is broken, as you suggested maybe it is a theming problem ? Can you run without any custom themes and see if that helps ?

klochowicz commented 7 months ago

FWIW I have managed to run the latest main branch example qml-features just fine after using Qt online installer (6.6.0) with gcc_64 , both in debug and release builds on my Ubuntu WSL2 environment.