您好,欢迎来到尚车旅游网。
搜索
您的当前位置:首页QTcpSocket client

QTcpSocket client

来源:尚车旅游网
#include \"widget.h\" #include \"ui_widget.h\"

Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {

ui->setupUi(this); }

Widget::~Widget() {

delete ui; }

void Widget::read() {

QString s = socket->readAll(); str += s;

ui->label->setText(s); }

void Widget::on_pushButton_clicked() {

socket = new QTcpSocket;

socket->connectToHost(\"192.168.1.22\",1234);

connect(socket,SIGNAL(readyRead()),this,SLOT(read()));

connect(socket,SIGNAL(connected()),this,SLOT(connected()));

connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected())); }

void Widget::connected() {

ui->label->setText(\"1111111111\"); }

void Widget::on_pushButton_2_clicked() {

n =socket->write(\"login|fljdslkj|fsdfsdf|\"); socket->waitForBytesWritten(100); socket->flush();

}

void Widget::on_pushButton_3_clicked() {

socket->write(\"chat|fljdslkj|liubing11111111|\"); socket->waitForBytesWritten(100); socket->flush(); }

void Widget::disconnected() {

ui->label->setText(\"已断开\"); }

void Widget::on_pushButton_4_clicked() {

socket->close();

socket->deleteLater(); }

void Widget::on_pushButton_5_clicked() {

n =socket->write(\"login|fljdslkj|fsdf|\"); socket->waitForBytesWritten(100); socket->flush(); }

void Widget::on_pushButton_6_clicked() {

socket->write(\"login|fljdslkj|fsdf|\"); socket->waitForBytesWritten(100); socket->flush(); }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- sceh.cn 版权所有 湘ICP备2023017654号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务