C++ Qt - QTcpSocket - File not found
15,152
You need
QT += network
in your .pro file. Otherwise the module in which those headers are defined/libraries are built won't be loaded.
Author by
Béatrice Moissinac
Graduate Student in Machine Learning at Oregon State University
Updated on June 24, 2022Comments
-
Béatrice Moissinac almost 2 years
I am using
Qt
andQTcpSocket
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 <QTcpSocket>
.Where is this library located and how can I install it?
-
Béatrice Moissinac over 11 yearsIndeed, you are right. I still get main.cpp:3:22: fatal error: QTcpSocket: No such file or directory. Ah! That's funny! So I modify my .pro, save, and run qmake -project, qmake and make in my terminal, and it changes my .pro back to before!
-
Béatrice Moissinac over 11 yearsI don't have this problem if I compile inside Qt Creator. Closing and restarting it does not affect this issue. Why are my changes not accepted by qmake -project?
-
Matt Phillips over 11 years@Bibi541 What? .pro files aren't auto-generated in any way that I've ever heard. Something isn't right--you didn't forget to save changes or something simple like that did you?
-
Béatrice Moissinac over 11 yearsWhat is different when I compile it with Qt Creator? Is it possible that the Makefile does not get updated?
-
Matt Phillips over 11 years@Bibi541 I almost always use QtCreator, but when I have compiled/run qmake from the command line, I've never seen what you just described. I think running qmake should always generate a new makefile--that's the point right? Also auto-generated are the
.pro.user
files, you didn't get mixed up with one of those somehow did you? -
Béatrice Moissinac over 11 yearsNo, because I modified my .pro in Qt Creator, which only shows the .pro in the project. There is no way I changed .pro.user instead. Strange...
-
Béatrice Moissinac over 11 yearsThe only reason why I was typing the command line is because somehow my images where not loading when running it with QtCreator, but loading when doing it by hand. Well, I will compile with QtCreator for now, and if I need to load my images, I guess I will come back to stackoverflow and ask :)
-
Matt Phillips over 11 years@Bibi541 Yes these kinds of issues with Qt pop up from time to time and can be pretty annoying. Good luck!