ROOT header files not found when compiling in Qt Creator

Hi all,

I’m a summerstudent working on an existing code (C++) with Qt Creator. The goal is to embed a ROOT canvas within the Qt created application/program. There are two examples (similar to each other) that I’ve tried: qtcanvas from Github and qtcanvas from Gitlab.

If anyone experienced with ROOT and/or Qt knows what is breaking, or knows an alternative way implement ROOT in a QtWidget: your expertize would be greatly appreciated.

Both examples produce the following errors during compilation:

TCanvas.h: No such file or directory                            qtcanvas.hpp 13
TApplication.h: No such file or directory                       main.cpp     10

I’ve installed ROOT in /usr/local/ and used $ source /usr/local/root/bin/thisroot.h. ROOT works on terminal and the headers and libraries are in place. I’ve tried different versions of Qt and different compilers; they produce the same error.

I’ve managed to solve this bug for the older version of qtcanvas (github), by adding the following lines to CMakeList.txt:

find_package(ROOT REQUIRED)

This produced 62 errors concerning TString.h , for example:

'string_view' in namespace 'std' does not name a type             TString.h 291
expected type-specifier                                           TString.h 118

An example of compile output:

/usr/local/root/include/RConfigure.h:30:4: warning: #warning is a GCC extension
   30 | #  warning "The C++ standard in this build does not match ROOT configuration (201703L); this might cause unexpected issues"
      |    ^~~~~~~
/usr/local/root/include/RConfigure.h:30:4: warning: #warning "The C++ standard in this build does not match ROOT configuration (201703L); this might cause unexpected issues" [-Wcpp]

Thank you in advance,

ROOT Version: v6.28/04
Platform: Ubuntu v22.04
Compiler: GCC v11.3.0, Clang14 and MinGW
Qt Version: Qt v5.15.2 and v6.2.4

Did you call source before starting QtCreator from the terminal?

Try also out this example which uses more modern CMake commands: ROOT · Modern CMake

Maybe share with us what is the “Build Environment” (make a screenshot) of the corresponding tab in QtCreator and “CMake configuration”. There should be some include_path there pointing at the ROOT include headers.

Also, are the warnings just warnings, or are you getting a compilation error?

I did call $ source and it is in my .bashrc. When calling $ root it runs.

Try the following fork to see if this one compiles for you:

It works for me out of the box with Ubuntu22 and ROOT 6.26/10 and QtCreator 10.0.1


Out of the box, I get the message that the cpp and hpp file cannot be found. I’ve changed the .pro file to include the directories /src and /include. Same thing has been done in the code, e.g. #include "include\qtcanvas.hpp"

Thereafter I get the TCanvas.h and TApplication.h errors. I tried it now on Windows 10, which has the same Qt Creator as you (10.0.2), and the errors persist.

Please do no use any .pro file, just clone freshly the repository I mentioned. From QtCreator, open the CMakeLists.txt directly by clicking on File, Open File or Project, doble click on CMakeLists.txt.

Thank you for your reply and help so far.

I get the following error on Ubuntu 22.04 (QtCreator 6.0.2):

Do I need to make a cmake configuration? I have no experience with this.

QtCreator needs a “Kit” where you define what compiler and what cmake version you are going to use.

You have to specify that under Tools, Preferences, Kits.

See e.g. below, my “Kit” uses as CMake Tool /usr/local/bin/cmake and as generator “Ninja”.

Problem has been fixed by building ROOT from source, instead of using binaries.

Thanks everyone for the help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.