Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in finding QDomDocument in c++ code

Tags:

c++

qt

I am using Qt for reading a Xml file in C++ code. I downloaded and installed Qt5 completely. Now, I add this line to my C++ code as a header:

#include <QtXml/QDomDocument>

even I add its path in command prompt:

export CPATH="/home/shirin/qt5"

but still receive this error:

fatal error: QtXml/QDomDocument: No such file or directory

Can anyone tell me how to fix it, please?

like image 689
shirin Avatar asked Jun 25 '26 20:06

shirin


2 Answers

Add QT += xml into your .pro file, run qmake and re-build. Also there is no need for the module in the include: #include <QDomDocument> should do the trick.

like image 88
Zlatomir Avatar answered Jun 28 '26 08:06

Zlatomir


If you're building with cmake, the Xml package must be found, and the corresponding library Qt5::Xml must be linked. (See here for the complete doc).

Here is an example if you're building a library using Qt with cmake. Note that I add Core in the example since it has to be here if you use Qt. Your list of Qt modules might of course be longer.

find_package(Qt5 COMPONENTS Core Xml REQUIRED)

# ...

add_library(mylib)
target_link_libraries(mylib, Qt5::Core Qt5::Xml)

Note If cmake cannot find the Qt packages, you might have to tweak the CMAKE_INSTALL_PREFIX, i.e.

cmake -DCMAKE_INSTALL_PREFIX=/path/to/Qt /path/to/src
like image 44
jmon12 Avatar answered Jun 28 '26 09:06

jmon12