- /**********************
- *Write to 5 July 2012*
- *By Mr Rao *
- **********************/
- #ifndef _CLIENT_H_
- #define _CLIENT_H_
- #include <QDialog>
- #include <QPushButton>
- #include <QTextEdit>
- #include <QLineEdit>
- #include <QLabel>
- #include <QVBoxLayout>
- #include <QHBoxLayout>
- #include <QTcpSocket>
- class Dialog:public QDialog
- {
- Q_OBJECT
- public:
- Dialog();
- ~Dialog();
- public slots:
- void send_slot();
- void connect_slot();
- private:
- QLabel *lab;
- QLabel *lab1;
- QLineEdit *lineEdit;
- QLineEdit *lineEditPort;
- QPushButton *connectButton;
- QPushButton *sendButton;
- QPushButton *exitButton;
- QTextEdit *textEdit;
- QTcpSocket *tcpSocket;
- QString strIP;
- QString strPort;
- };
- #endif
- #include "client.h"
- Dialog::Dialog()
- {
- connectButton = new QPushButton("connect");
- sendButton = new QPushButton("send");
- exitButton = new QPushButton("exit");
- lab = new QLabel(tr("To:"));
- lab1 = new QLabel(tr("Port:"));
- lineEdit = new QLineEdit;
- lineEditPort = new QLineEdit;
- textEdit = new QTextEdit;
- QHBoxLayout *topLayout = new QHBoxLayout;
- topLayout->addWidget(lab);
- topLayout->addWidget(lineEdit);
- topLayout->addWidget(lab1);
- topLayout->addWidget(lineEditPort);
- QHBoxLayout *centLayout = new QHBoxLayout;
- centLayout->addWidget(textEdit);
- QHBoxLayout *lastLayout = new QHBoxLayout;
- lastLayout->addWidget(connectButton);
- lastLayout->addWidget(sendButton);
- lastLayout->addWidget(exitButton);
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addLayout(topLayout);
- mainLayout->addLayout(centLayout);
- mainLayout->addLayout(lastLayout);
- setLayout(mainLayout);
- sendButton->setDisabled(false);
- tcpSocket = new QTcpSocket;
- connect(connectButton,SIGNAL(clicked()),this,SLOT(connect_slot()));
- connect(sendButton,SIGNAL(clicked()),this,SLOT(send_slot()));
- connect(exitButton,SIGNAL(clicked()),this,SLOT(close()));
- }
- Dialog::~Dialog()
- {
- delete lab;
- delete lineEdit;
- delete connectButton;
- delete sendButton;
- delete exitButton;
- delete textEdit;
- delete tcpSocket;
- }
- void Dialog::connect_slot()
- {
- this->strIP = this->lineEdit->text();
- this->strPort = this->lineEditPort->text();
- tcpSocket->connectToHost(strIP , this->strPort.toInt(0 , 10));
- }
- void Dialog::send_slot()
- {
- QString catstr = textEdit->toPlainText();
- tcpSocket->write(qPrintable(catstr));
- }
- #include <QApplication>
- #include "client.h"
- int main(int argc,char **argv)
- {
- QApplication app(argc,argv);
- Dialog dlg;
- dlg.show();
- return app.exec();
- }