qtクライアントの実装
1、 .hファイル
2、cppファイル
#ifndef CLIENT_H
#define CLIENT_H
#include
#include
namespace Ui {
class client;
}
class client : public QWidget
{
Q_OBJECT
public:
explicit client(QWidget *parent = 0);
~client();
private slots:
void on_Button_Connect_clicked();
void on_Button_Close_clicked();
void on_Button_Send_clicked();
private:
Ui::client *ui;
QTcpSocket *sock;
};
#endif // CLIENT_H
2、cppファイル
#include "client.h"
#include "ui_client.h"
#include
client::client(QWidget *parent) :
QWidget(parent),
ui(new Ui::client)
{
ui->setupUi(this);
sock = NULL;
sock = new QTcpSocket(this); //set a client object
}
client::~client()
{
delete ui;
}
void client::on_Button_Connect_clicked()
{
//get ip and port
QString ip = ui->le_IP->text();
qint16 port = ui->le_port->text().toInt();
//connect with sever
sock->connectToHost(QHostAddress(ip),port);
}