Qt - QTcpSocket - File not found
Contents
I am using Qt’s QTcpSocket class to create a small chat client/server application. When I compile my code, the compiler returns the following error:
main.cpp:3:22: fatal error: QTcpSocket: No such file or directory
This refers to #include
Where is this library located and how can I install it?
After google it, we just need to add
QT += network
in the .pro file which is generated by
qmake -project
. Otherwise the module in which those headers are defined/libraries are built won’t be loaded.
NOTICE: If you use qmake -project after you modified .pro file, you will still get the above error. Because using qmake -project will change the .pro file back to before!
The commands I used is described in my article:
qmake -project qmake -tp vc
The problem described above is solved. Just keep in mind that qmake -project is used to generate .pro file and qmake -tp vc is used to generate Visual Studio project file.
Author Watterry
LastMod 2012-12-21