Qt的tcpclient demo
来源:互联网 发布:西安交通大学网络认证 编辑:程序博客网 时间:2024/04/29 18:59
mainwindow.cpp
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::connectHost()
- {
- this->connectSocket = new QTcpSocket;
- this->connectSocket->connectToHost(QHostAddress("192.168.1.36"),8888);
- QObject::connect(this->connectSocket,SIGNAL(connected()),this,SLOT(processConnection()));
- }
- #include <QByteArray>
- void MainWindow::processConnection()
- {
- QByteArray *array =new QByteArray;
- array->clear();
- array->append(ui->lineEdit->text());
- // ui->lineEdit->text(); // QString
- this->connectSocket->write(array->data());
- }
- void MainWindow::on_pushButton_clicked()
- {
- this->connectHost();
- }
mainwindow.h
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QtNetwork/QTcpSocket>
- #include <QtNetwork/QHostAddress>
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- private:
- Ui::MainWindow *ui;
- QTcpSocket *connectSocket;
- private slots:
- void on_pushButton_clicked();
- void processConnection();
- void connectHost();
- };
- #endif // MAINWINDOW_H
main.cpp
- #include <QtGui/QApplication>
- #include "mainwindow.h"
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
0 0
- Qt的tcpclient demo
- Qt的tcpclient demo
- 基于TCPClient的客户端服务器的简单通信demo
- Qt 实现TcpServer与TcpClient
- Qt的tcpserver demo
- 编译Qt的Demo
- Qt的tcpserver demo
- Qt的打印机Demo
- C#的TCPClient连接
- tcpClient的使用
- TCPClient
- .NET中TCPClient的源代码
- TcpClient tcpClient
- QT Demo
- Qt的http下载的Demo
- Qt 截取屏幕的小demo
- Qt与Qml交互的小Demo
- Qt实现TcpClient和TcpServer连接收发数据
- 批处理 记录 事件日期,保存事件明细
- Flashback Database
- The method of type must override a superclass method 解决方式
- Cracking The Coding Interview 1.5
- 关于野指针
- Qt的tcpclient demo
- 设计模式之(Singleton单例模式)
- [LeetCode] Remove Duplicates from Sorted List
- C++含有const的传递和返回
- windows系统下简单nodejs环境配置安装
- nginx loction语法详解
- 2011-10-15腾讯校园招聘笔试题目与参考答案
- C++类实现最大数的输出
- 多重安全保障 天锐移动终端安全管理系统让移动办公时代马上到来