Qt のクライアント用にこのプログラムを作成しましたが、コンパイルしていません。プログラムの後に与えられるエラー。
誰かが私を助けることができますか?
MyClient.h:
//MyClient.h
#ifndef CLIENT_H
#define CLIENT_H
#include <QObject>
class QTcpSocket;
class Client : public QObject
{
Q_OBJECT
public:
explicit Client(QObject *parent = 0);
void connectToServer();
signals:
public slots:
void on_connected();
private:
QTcpSocket* socket;
};
#endif // CLIENT_H
MyClient.cpp:
//MyClient.cpp
#include "MyClient.h"
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QHostAddress>
#include <cstdio>
#include<cstring>
Client::Client(QObject *parent) :
QObject(parent)
{
socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()),
this, SLOT(on_connected()));
}
void Client::on_connected()
{
printf("Connection established.\n");
char buffer[1024];
forever
{
printf(">> ");
gets(buffer);
int len = strlen(buffer);
buffer[len] = '\n';
buffer[len+1] = '\0';
socket->write(buffer);
socket->flush();
}
}
void Client::connectToServer()
{
socket->connectToHost(QHostAddress::LocalHost, 1234);
}
主要
//main
#include "tcpclient.h"
#include <QApplication>
#include <QtCore/QCoreApplication>
#include "MyClient.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Client c;
c.connectToServer();
return a.exec();
}
エラー:
MyClient.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall Client::Client(class QObject *)" (??0Client@@QAE@PAVQObject@@@Z)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QTcpSocket::metaObject(void)const " (?metaObject@QTcpSocket@@UBEPBUQMetaObject@@XZ)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall QTcpSocket::qt_metacast(char const *)" (?qt_metacast@QTcpSocket@@UAEPAXPBD@Z)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall QTcpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QTcpSocket@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UBE_NXZ)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void __thiscall QAbstractSocket::close(void)" (?close@QAbstractSocket@@UAEXXZ)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UBE_NXZ)
MyClient.obj:-1: error: LNK2001: unresolved external symbol "public: virtual __int64 __thiscall QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UBE_JXZ)