간단한 Tcp 통신 프로젝트를 만들고 싶지만 몇 가지 문제가 있으며 그 문제를 해결하는 방법을 모른다. 솔루션을 찾으려고 할 때 모든 사람들이 .pro 파일에이 코드 (QT + = network)를 추가하라고 지시하지만 ui 프로젝트에서는 프로 파일이 없으므로 해결책을 찾을 수 없습니다.qt ui 프로젝트와 간단한 tcp 통신
//commu.h
#ifndef COMMU_H
#define COMMU_H
#include <QtWidgets/QMainWindow>
#include "ui_commu.h"
#include <QtNetwork/QTcpSocket>
#include <QObject>
#include <QString>
class commu : public QMainWindow
{
Q_OBJECT
public:
commu(QWidget *parent = 0);
~commu();
void start(QString address, quint16 port);
private:
Ui::commuClass ui;
QTcpSocket client;
public slots:
void startTransfer();
};
#endif // COMMU_H
//commu.cpp
#include "commu.h"
#include <QtNetwork/QHostAddress>
commu::commu(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(&client, SIGNAL(connected()),this,SLOT(startTransfer()));
}
commu::~commu()
{
client.close();
}
void commu::start(QString address, quint16 port)
{
QHostAddress addr(address);
client.connectToHost(addr, port);
}
void commu::startTransfer()
{
client.write("Hello, world", 13);
}
//main.cpp
#include "commu.h"
#include <QtWidgets/QApplication>
#include <QtCore>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
commu w;
w.show();
return a.exec();
commu client;
client.start("127.0.0.1", 8888);
}
나는 오류를 얻을 :
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" ([email protected]@[email protected]) referenced in function "public: virtual __thiscall commu::~commu(void)" ([email protected]@[email protected])
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" ([email protected]@[email protected]@@@Z) referenced in function "public: __thiscall commu::commu(class QWidget *)" ([email protected]@[email protected]@@@Z)
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" ([email protected]@[email protected]) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" ([email protected]@@[email protected]@[email protected])
1>commu.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" ([email protected]@[email protected]@@@Z) referenced in function "public: void __thiscall commu::start(class QString,unsigned short)" ([email protected]@@[email protected]@[email protected])
1>c:\users\sel\documents\visual studio 2010\Projects\commu\Win32\Debug\\commu.exe : fatal error LNK1120: 4 unresolved externals
을
qmake를 사용하여 프로젝트를 빌드하지 않는 이유는 무엇입니까? –
Qt 프로젝트에 Visual Studio를 사용하고 있습니다. 어떻게 사용할 수 있습니까? 나는 Qt에서 새로운 사람이다. – citi
Qt를 처음 접한다면 좀 더 많은 튜토리얼을 읽어야합니다. Visual Studio 용 Qt 통합 모듈이 있습니다. 아마 그것을 사용해야합니다. –