QT undefined reference errors when trying to compile

别说谁变了你拦得住时间么 提交于 2019-12-01 17:12:20

First you need to #include <QHostAddress> somewhere assuming that commented out line is what caused the problem.

You may also to check some project settings to see if you have all the correct inputs.

Edit: More detail

QtNetwork requires QT network lib inputs. Assuming once again that you are using QtCreator as not much info was provided then this means in your .pro file you need to have a line like so:

QT += network

Then make sure you include the right headers for the objects you are using before using them. If you still get undefined references, linking errors, etc try a QMake and rebuild. If it still persists you probably have errors in your code in addition to QT usage errors and should validate that your methods and objects being used were properly declared.

Final Edit: Glad that worked ...

When you create a new project in QTCreator there is a step in the wizard where you can check off the various QT libraries you want to include which will add these .pro lines and inputs for you. This is QT version of inputting additional lib files and by default they will be statically linked I believe. If you want to dynamically link with shared objects or dll then there is some extra configuration steps.

Are you running the moc tool over your header file? Are you subsequently compiling the output from the moc tool?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!