QT undefined control errors when trying to compile

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

release / icecastserver.o: icecastserver.cpp :(. text + 0x39): undefined link to _imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x50): undefined reference to imp ZN12QH14dressdresspecial Special : icecastserver.cpp :( text + 0x68): undefined link to _imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x73): undefined reference to _imp _ZN12QHostAddresserererer ice ice1 ice . text + 0x9d): undefined _imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x3d4): undefined reference to imp ZN12QHostAddressD1Ev 'release / icecastserver.o: 0x4ppserver.o: 0 0x4ppserver.o: icecastserver.o: 0x4ppserver) undefined reference to _imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x4d4): undefined reference to _imp _ZN12QHostAddressC1ENS_14SpecialAddressE' releas e / icecastserver.o: icecastserver.cpp :( text + 0x4ec): undefined link to _imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x4f7): undefined reference to impverD112 ice icecastserver.cpp :(. text + 0x521): undefined reference to _imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x858): undefined reference to

What am I doing wrong?

This is the header file:

 #ifndef ICECASTSERVER_H #define ICECASTSERVER_H #include <QObject> QT_BEGIN_NAMESPACE class QTcpServer; QT_END_NAMESPACE class IcecastServer : public QObject { Q_OBJECT public: explicit IcecastServer(QObject *parent = 0); signals: public slots: private: QTcpServer *tcpServer; }; #endif // ICECASTSERVER_H 

This is the source file:

 #include "icecastserver.h" #include "QDebug" #include <QtNetwork/QTcpServer> #include <QtGui> IcecastServer::IcecastServer(QObject *parent) : QObject(parent) { tcpServer = new QTcpServer(this); //tcpServer->listen(QHostAddress::Any,8000); if (!tcpServer->listen()){ QMessageBox::critical(NULL, tr("Fortune Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString())); return; } } 
+6
source share
2 answers

First you need #include <QHostAddress> , where it is assumed that the missing line is what caused the problem.

You can also check some project parameters to see if you have all the correct inputs.

Edit: Details

QtNetwork requires a QT network. Assuming once again that you are using QtCreator since no information was provided, this means that in your .pro file you need to have this line:

QT += network

Then make sure that you use the correct headers for the objects you are using before using them. If you still get undefined links, error binding, etc. Try QMake and rebuild. If it still persists, you probably have errors in your code in addition to errors in using QT, and you should check that your methods and objects are declared correctly.

Final Edit: Glad it worked ...

When you create a new project in QTCreator, there is a step in the wizard where you can check out the various QT libraries that you want to include, which will add these .pro lines and inputs for you. This is the QT version for inputting additional lib files, and by default they will be statically linked, I suppose. If you want to dynamically communicate with shared objects or dlls, then there are additional configuration steps.

+7
source

Do you moc tool on your header file? Do you subsequently compile the output from the moc tool?

+1
source

Source: https://habr.com/ru/post/885869/


All Articles