QT undefined reference errors when trying to compile

前端 未结 2 1707
清歌不尽
清歌不尽 2021-01-18 09:56

I added a class IcecastServer to my QT-project, added the header-file to the pro file and added some code. Everytime I compile it the following errors occur:

相关标签:
2条回答
  • 2021-01-18 10:29

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

    0 讨论(0)
  • 2021-01-18 10:30

    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.

    0 讨论(0)
提交回复
热议问题