📄 ab.cpp
字号:
#include "ab.h"MyMainWindow::MyMainWindow() { setGeometry(0,0,640,480); inText=new QLabel (this); inText->setGeometry(10,30,100,10); inText->setText(tr("Input Text")); outText=new QLabel (this); outText->setGeometry(10,80,100,10); outText->setText(tr("Output Text")); stateShow=new QLabel (this); stateShow->setGeometry(10,380,100,10); stateShow->setText(tr("stateShow")); inputText=new QLineEdit(this); inputText->setGeometry(100,30,300,50); outputText=new QLineEdit(this); outputText->setGeometry(100,80,300,50); connectButton=new QPushButton("Connect",this); connectButton->setGeometry(50,420,100,25); exitButton=new QPushButton("Send",this); exitButton->setGeometry(350,420,100,25); connectionTimer =new QTimer(this); connectionTimer->start(300,true); sendTimer =new QTimer(this); //sendTimer->start(500,true); ClientSocket= new QSocket(this); ClientSocket->connectToHost("192.168.1.9",10001); //connect(connectButton,SIGNAL(clicked()),this,SLOT(Conne())); //connect(exitButton,SIGNAL(clicked()),this,SLOT(dataSend())); connect(ClientSocket,SIGNAL(readyRead()),this,SLOT(dataGet())); connect(connectionTimer,SIGNAL(timeout()),this,SLOT(timerOut())); connect(sendTimer,SIGNAL(timeout()),this,SLOT(dataSend()));}void MyMainWindow::Conne(){ // ClientSocket->connectToHost("192.168.1.9",10001);}void MyMainWindow::dataSend(){ printf("%s\n","abc"); ClientSocket->writeBlock(inputText->text(),1024); sendTimer->stop();}void MyMainWindow::dataGet(){ char abc[1050];//s.resize( ClientSocket->bytesAvailable());// Q_ULONG abc=16; ClientSocket->readBlock(abc,ClientSocket->bytesAvailable()); sendTimer->start(500,true); printf("%s\n",abc); //ab.append(abc); //if (abc[0]=0x55) //{ inputText->setText(abc); //}}void MyMainWindow::timerOut(){ switch(ClientSocket->state()) { case QSocket::Idle: stateShow->setText(tr("Idle")); break; case QSocket::HostLookup: stateShow->setText(tr("HostLookup")); break; case QSocket::Connecting: stateShow->setText(tr("Connecting")); break;// case QSocket::Connected:// stateShow->setText(tr("Connected"));// break; case QSocket::Closing: stateShow->setText(tr("Closing")); break; default: stateShow->setText(tr("Connected")); } connectionTimer->start(500,true);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -