Embedding ROOT in QT on windows

ROOT Version: 6.22.08
Platform: Windows 10
Compiler: MSCV2019 16 x86

Dear @linev,
You recently explained to me in the post HERE how to embed RCanvas, TCanvas and RGeomViewer inside QT. I thank you for this as your explanations were of great help to me. I was using LINUX and everything worked perfectly.
Today, I am trying to perform the same on windows. I have compiled successfully ROOT with qt5web, root7, and webgui.
However, I am asking for your help again regarding the compilation of the example you provided.
When I try to compile the project, the following error happens:

Conversion of ‘int’ to ‘_Ty’ requires a narrowing conversion

This happens for Canvas->SetSize({width(), height()})
I can solve it by writting:
Canvas->SetSize({(ROOT::Experimental::RPadLength::Pixel)width(), (ROOT::Experimental::RPadLength::Pixel)height()})

Am I missing something or is it not planned to work on windows?
Thanks a lot in advance for your help.

1 Like

In fact the compilation works but not the execution. I do not know if this comes from my modification (I doubt). I send you a picture of the crash, maybe you already got this?

Hi Thomas,

I have another application, where I using component similar to TCanvasWidget.
And I test it on all supported platforms - Linux, Mac and Windows.
But I didnot test qt5web tutorial directly.

Your changes like (ROOT::Experimental::RPadLength::Pixel)width() should be fine - seems to be on windows QWidget returns size as float. Could you check that width() and height() returns reasonable values here. Or just replace them with some fixed values like 600 and 400

I will try to run my Windows VM, but it could take time.


Dear Sergey,
Thanks a lot for your fast reply. Unfortunately, I cannot test what width() and height() returns because, despite the application compiles, it does not run.
I believe the error I encountered is not linked with the int conversion. Maybe it could originate from a problem in visual studio as the exception occurs with RtlZeroMemory which seems to be a pure windows routine.
I will keep you informed if I come with a solution.

I performed some additional tests by removing every root object from qt5web. It happens that as long as I do not include a root header, the program runs. At the moment I include the root headers (TApplication.h, TSystem.h, TF1.h …etc), the program gives the error I posted above.
I do not understand why and maybe this is originating from a wrong .pro file?
I used the .pro file from the qt5web example and added:



win32: LIBS += -L$${ROOTSYS}/lib/ -llibCore
win32: LIBS += -L$${ROOTSYS}/lib/ -llibImt
win32: LIBS += -L$${ROOTSYS}/lib/ -llibRIO
win32: LIBS += -L$${ROOTSYS}/lib/ -llibHist
win32: LIBS += -L$${ROOTSYS}/lib/ -llibGraf
win32: LIBS += -L$${ROOTSYS}/lib/ -llibGpad
win32: LIBS += -L$${ROOTSYS}/lib/ -llibMatrix
win32: LIBS += -L$${ROOTSYS}/lib/ -llibMathCore
win32: LIBS += -L$${ROOTSYS}/lib/ -llibThread
win32: LIBS += -L$${ROOTSYS}/lib/ -llibGeom
win32: LIBS += -L$${ROOTSYS}/lib/ -llibROOTWebDisplay
win32: LIBS += -L$${ROOTSYS}/lib/ -llibROOTGpadv7
win32: LIBS += -L$${ROOTSYS}/lib/ -llibROOTBrowserv7
win32: LIBS += -L$${ROOTSYS}/lib/ -llibROOTEve
win32: LIBS += -L$${ROOTSYS}/lib/ -llibWebGui6

It seems the problem comes from TVersionCheck.h as, when I remove the code line inside this header, including the other header such as TApplication.h for instance, does not lead to a crash at execution. I suspect that I do not compile my qt5web with the same compiler I used to build root…
I compile root with:

cmake -A Win32 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_CXX_STANDARD=14 -Dqt5web=ON -Dwebgui=ON -Droot7=ON -DQt5_DIR=C:\Qt\5.15.0\msvc2019\lib\cmake\Qt5 ../root-master
cmake --build . --config Release -- /maxcpucount

And I compile qt5web with Qt5.15.0 MSVC2019 32bit

Thanks for your help

Hi Thomas,

I create cmake file to compile qt5web application.

CMakeLists.txt (687 Bytes)

You should try to use it. On Windows you have to use following commands for compilation in “Native Tools x86 command line” of VC:

set PATH=%PATH%;C:\Qt\5.12.6\msvc2017\bin
call c:\root\bin\thisroot.bat
cmake -G"Visual Studio 16 2019" -A Win32 -Thost=x64  c:\git\root\tutorials\webgui\qt5web
cmake --build . --config Debug -- /maxcpucount

Please try to see if it will work for you.
On my Window VM I have some problem and need to investigate further.


Hello Sergey,

Unfortunately, it creates the same behavior as when I compile with QtCreator.
I compiled the qt5web application within the x86 command prompt for VS2019 linking with Qt5.15.0. I also tried with cmake-gui launched from the x86 command prompt for VS2019. Both compilations (cmake and cmake-gui) are going perfectly, in release or debug mode.
However, when I launch the executable, the “Root session” prompt appears and then closes without any further message. The qt5web program is executed (I see it in my task manager) and then killed. The crash does not indicate anything.
Could it be from our version of MSVC or QT? You use MSVC2017 with Qt5.12.6 and I use MSVC2019 with Qt5.15.0.
Thanks again for your availability and help.

Hi Thomas,

I upgrade my VC and Qt5 installations to recent ones - now I using Qt5.15.2 and latest MSVC2019.
I manage to compile ROOT and it works for me.
Also root --web=qt5 works properly - after one types new TBrowser Qt5 web engine widgets are used to show it.

But separate qt5web.exe does not work - it crashes in very early stage.
I suspect mismatch in compilation flags, but have no much experience there.
Probably, we should ask our Windows expert Bertrand @bellenot to see why it could happen.
I create branch with all necessary changes.


Hi, yes this might well be a compilation flag issue, I’ll have to try myself. But before that, could you try to add these lines at the beginning of your CMakeLists.txt

find_package(ROOT REQUIRED)

To see if it changes anything?

Unfortunately, it does not change anything.

OK, thanks for trying. Then I’ll have to try, but it will take some time. Stay tuned

I could provide call stack at point where it crashes, but crash happens in absolutely legal place and therefore I cannot understand it

If it’s the same than the one previously posted here, it’s useless, I’ll have to catch the error and debug it

ROOT compiler flags seems to be assigned properly after doing:


Right, sorry, I forgot this. Here is what I have in most of my various CMakeLists.txt:

# Check if cmake has the required version

set(PROJECT_NAME View3ds)

find_package(ROOT REQUIRED)



# create dictonary

add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cxx ${PROJECT_NAME}Dict.cxx ${PROJECT_NAME}.rc)
target_link_libraries(${PROJECT_NAME} ${ROOT_LIBRARIES} libEve libGui libGed libRGL)

(I removed several not relevant lines)

But is it working then?

No, it is not work.

All your additional settings requires to build dictionary or extra library, which are not present here

1 Like

Well, OK, it was just an example…

So taking Qt5.15.2, VS2019 v16.9.3, ROOT master + latest changes from Sergey, built in Release mode, it just works, see the screenshot:

1 Like

Grate that it works, thanks Bertrand for testing it!

I was building in Debug mode, will try Release now.
But most probably my VM has problems.

I will apply changes to master and 6.24 branch