📄 frmclient.cpp
字号:
#include "frmclient.h"/* * Constructs a frmclient which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */static const Q_UINT16 ipcPort = 8000;frmclient::frmclient( QWidget* parent, const char* name, bool modal, WFlags fl ) : clientform( parent, name, modal, fl ){ socket =new QSocket (this); connectFlag=FALSE; connect( socket, SIGNAL(connected()), this ,SLOT(SocketConnected())); connect( socket, SIGNAL(connectionClosed()), this, SLOT(ServerConnectionClosed()) ); connect( socket, SIGNAL(error(int)), this ,SLOT(SocketError(int)) ); connect( btnSendPicture, SIGNAL(clicked()), SLOT(sendImage()) ); connect( btnSendText, SIGNAL(clicked()), SLOT(sendText()) ); connect( btnSendFile, SIGNAL(clicked()), SLOT(sendFile()) ); connect( btnConnect, SIGNAL( clicked()), SLOT( connectNet())); connect( btnExit, SIGNAL( clicked()), SLOT(exitSystem())); socket->connectToHost( "196.168.0.100", ipcPort );}/* * Destroys the object and frees any allocated resources */frmclient::~frmclient(){ // no need to delete child widgets, Qt does it all for us}void frmclient::ServerConnectionClosed(){ connectFlag=FALSE; txtContent->append (tr("disconnect net")); }void frmclient::SocketConnected(){ connectFlag=TRUE; txtContent->append (tr("connect net"));}void frmclient::SocketError(int error){ txtContent->append( tr("Error number %1 occurred\n").arg(error) ); }void frmclient::connectNet(){ socket->connectToHost( "192.168.0.100", ipcPort ); }void frmclient::sendImage(){ QString imageName=txtContent->text(); QImage image( imageName ); if ( !image.isNull() ) { sendPacket( image ); } }void frmclient::sendText(){ if(connectFlag) sendPacket( txtContent->text() ); else txtContent->append (tr("Net is not connected"));}void frmclient::sendFile(){ txtContent->setText("");}void frmclient::sendPacket( const QVariant &v ){ QByteArray ba; QDataStream varDs( ba, IO_WriteOnly ); varDs << v; QDataStream ds( socket ); ds << (Q_UINT32) ba.size(); socket->writeBlock( ba.data(), ba.size() ); }void frmclient::exitSystem(){ close();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -