CLIENT
#include "dialog1.h"
#include "ui_dialog1.h"
#include "timeall.h"
#include<QByteArray>
#include <QFile>
#include <QTextStream>
Dialog1
::Dialog1(QWidget *parent
) : ui(new Ui::Dialog1)
{
ui->setupUi(this);
sock->connectToHost("localhost", 40000);
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(on_pushButton_2_clicked()));
}
Dialog1::~Dialog1()
{
delete ui;
sock->close();
}
void Dialog1
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void Dialog1::on_pushButton_clicked()
{
//Time Advanced
timeall *t1=new timeall;
t1->setModal(true);
t1->show();
q=ui->lineEdit_3->text();
s=ui->lineEdit_2->text();
if(s==NULL)
{
q.clear();
o.clear();
d="date +%Y%m%d -s ";
t=ui->lineEdit_4->text();
o+=t;
t=ui->lineEdit_3->text();
o+=t;
t=ui->lineEdit->text();
o+=t;
d+=o;
out<<d;
/*sock->write(block);
sock->close();*/
// system(m);
//d.clear();
// o.clear();
//t.clear();
}
else if(q==NULL)
{
d="date +%T -s ";
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
d+=o;
//const char *m = d.toLatin1();//Qstring to const *char
block.append(d);
//sock->write(block);
//sock->close();
}
else
{
d="date ";
o+=q;
q=ui->lineEdit->text();
o+=q;
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
q=ui->lineEdit_4->text();
o+=q;
d+=o;
block.append(d);
// sock->write(block);
// sock->close();
}
}
void Dialog1::on_pushButton_2_clicked()
{
q=ui->lineEdit_3->text();
s=ui->lineEdit_2->text();
if(s==NULL)
{
q.clear();
o.clear();
t=ui->lineEdit_4->text();
o+=t;
t=ui->lineEdit_3->text();
o+=t;
t=ui->lineEdit->text();
o+=t;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
block.append(d);
sock->write(block);
sock->close();
// system(m);
d.clear();
o.clear();
t.clear();
}
else if(q==NULL)
{
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
block.append(d);
sock->write(block);
sock->close();
//system(m);
d.clear();
o.clear();
q.clear();
}
else
{
o+=q;
q=ui->lineEdit->text();
o+=q;
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
q=ui->lineEdit_4->text();
o+=q;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
block.append(d);
sock->write(block);
sock->close();
// system(m);
d.clear();
o.clear();
q.clear();
}
}
#include "dialog1.h"
#include "ui_dialog1.h"
#include "timeall.h"
#include<QByteArray>
#include <QFile>
#include <QTextStream>
QString q,s,t,o,d;
Dialog1::Dialog1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog1)
{
ui->setupUi(this);
sock = new QTcpSocket(this);
sock->connectToHost("localhost", 40000);
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(on_pushButton_2_clicked()));
}
Dialog1::~Dialog1()
{
delete ui;
sock->close();
}
void Dialog1::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void Dialog1::on_pushButton_clicked()
{
//Time Advanced
timeall *t1=new timeall;
t1->setModal(true);
t1->show();
QFile file("dd.txt");
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
q=ui->lineEdit_3->text();
s=ui->lineEdit_2->text();
if(s==NULL)
{
q.clear();
o.clear();
d="date +%Y%m%d -s ";
t=ui->lineEdit_4->text();
o+=t;
t=ui->lineEdit_3->text();
o+=t;
t=ui->lineEdit->text();
o+=t;
d+=o;
out<<d;
/*sock->write(block);
sock->close();*/
// system(m);
//d.clear();
// o.clear();
//t.clear();
}
else if(q==NULL)
{
d="date +%T -s ";
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
d+=o;
//const char *m = d.toLatin1();//Qstring to const *char
QByteArray block = "";
block.append(d);
//sock->write(block);
//sock->close();
}
else
{
d="date ";
o+=q;
q=ui->lineEdit->text();
o+=q;
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
q=ui->lineEdit_4->text();
o+=q;
d+=o;
QByteArray block = "";
block.append(d);
// sock->write(block);
// sock->close();
}
}
void Dialog1::on_pushButton_2_clicked()
{
q=ui->lineEdit_3->text();
s=ui->lineEdit_2->text();
if(s==NULL)
{
q.clear();
o.clear();
QString d="date +%Y%m%d -s ";
t=ui->lineEdit_4->text();
o+=t;
t=ui->lineEdit_3->text();
o+=t;
t=ui->lineEdit->text();
o+=t;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
QByteArray block = "";
block.append(d);
sock->write(block);
sock->close();
// system(m);
d.clear();
o.clear();
t.clear();
}
else if(q==NULL)
{
QString d="date +%T -s ";
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
QByteArray block = "";
block.append(d);
sock->write(block);
sock->close();
//system(m);
d.clear();
o.clear();
q.clear();
}
else
{
QString d="date ";
o+=q;
q=ui->lineEdit->text();
o+=q;
q=ui->lineEdit_2->text();
o+=q;
q=ui->lineEdit_5->text();
o+=q;
q=ui->lineEdit_4->text();
o+=q;
d+=o;
const char *m = d.toLatin1();//Qstring to const *char
QByteArray block = "";
block.append(d);
sock->write(block);
sock->close();
// system(m);
d.clear();
o.clear();
q.clear();
}
}
To copy to clipboard, switch view to plain text mode
//SERVER
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Set up connection
// If server does not listen
{
server->close();
return; // Leave constructor, e.g. if port is currently used
}
connect(server, SIGNAL(newConnection()), this, SLOT(on_new_connection()));
}
MainWindow::~MainWindow()
{
//delete ui;
server->close();
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
//ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_new_connection()
{
sock = server->nextPendingConnection();
connect(sock, SIGNAL(readyRead()), this, SLOT(on_ready_read()));
}
void MainWindow::on_ready_read()
{
sock->close();
//ui->label->setText(message);
const char *m = message.toLatin1();
system(m);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Set up connection
server = new QTcpServer(this);
// If server does not listen
if( !server->listen(QHostAddress::Any,40000))
{
server->close();
return; // Leave constructor, e.g. if port is currently used
}
connect(server, SIGNAL(newConnection()), this, SLOT(on_new_connection()));
}
MainWindow::~MainWindow()
{
//delete ui;
server->close();
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
//ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_new_connection()
{
sock = server->nextPendingConnection();
connect(sock, SIGNAL(readyRead()), this, SLOT(on_ready_read()));
}
void MainWindow::on_ready_read()
{
QByteArray msg=sock->readAll();
sock->close();
QString message(msg);
//ui->label->setText(message);
const char *m = message.toLatin1();
system(m);
}
To copy to clipboard, switch view to plain text mode
Bookmarks