qt simple tcp communication with ui projects
I want to create a simple Tcp Communication project but I get some problems and I dont know how to solve that problem. When I try to find solution all people tell add this code (QT += network)on .pro file but in ui projects I dont have any pro file so I dont know the find the solution.
//commu.h
Code:
#ifndef COMMU_H
#define COMMU_H
#include <QtWidgets/QMainWindow>
#include "ui_commu.h"
#include <QtNetwork/QTcpSocket>
#include <QObject>
#include <QString>
{
Q_OBJECT
public:
~commu();
void start
(QString address, quint16 port
);
private:
Ui::commuClass ui;
public slots:
void startTransfer();
};
#endif // COMMU_H
//commu.cpp
Code:
#include "commu.h"
#include <QtNetwork/QHostAddress>
{
ui.setupUi(this);
connect(&client, SIGNAL(connected()),this,SLOT(startTransfer()));
}
commu::~commu()
{
client.close();
}
void commu
::start(QString address, quint16 port
) {
client.connectToHost(addr, port);
}
void commu::startTransfer()
{
client.write("Hello, world", 13);
}
//main.cpp
Code:
#include "commu.h"
#include <QtWidgets/QApplication>
#include <QtCore>
int main(int argc, char *argv[])
{
commu w;
w.show();
return a.exec();
commu client;
client.start("127.0.0.1", 8888);
}
I get the errors:
Code:
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UAE@XZ) referenced in function "public: virtual __thiscall commu::~commu(void)" (??1commu@@UAE@XZ)
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall commu::commu(class QWidget *)" (??0commu@@QAE@PAVQWidget@@@Z)
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" (?start@commu@@QAEXVQString@@G@Z)
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" (?start@commu@@QAEXVQString@@G@Z)
1>c:\users\sel\documents\visual studio 2010\Projects\commu\Win32\Debug\\commu.exe : fatal error LNK1120: 4 unresolved externals
Re: qt simple tcp communication with ui projects
Quote:
Originally Posted by
citix
I want to create a simple Tcp Communication project but I get some problems and I dont know how to solve that problem. When I try to find solution all people tell add this code (QT += network)on .pro file but in ui projects I dont have any pro file so I dont know the find the solution.
What does "ui project" mean?
If you are using some other build system than qmake, then you need to add the linker directive for QtNetwork through that build system's means.
Cheers,
_