|
@@ -0,0 +1,111 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ socket_ = new QTcpSocket(this);
|
|
|
+// socket_->connectToHost("rtk.ntrip.qxwz.com",8002);
|
|
|
+ connect(socket_, SIGNAL(connected()), this, SLOT(connectedSlot()));
|
|
|
+ connect(socket_, SIGNAL(disconnected()), this, SLOT(disconnectedSlot()));
|
|
|
+ connect(socket_, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
|
|
+ connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
|
|
+ SLOT(errorSlot(QAbstractSocket::SocketError)));
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_pushButton_Update_clicked()
|
|
|
+{
|
|
|
+ ui->pushButton_Update->setEnabled(false);
|
|
|
+ ui->plainTextEdit->setPlainText("Connecting server...");
|
|
|
+
|
|
|
+ socket_->connectToHost("127.0.0.1",19100);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::connectedSlot()
|
|
|
+{
|
|
|
+ if(socket_->state() == QAbstractSocket::ConnectedState)
|
|
|
+ {
|
|
|
+ qDebug("main is connected.\n");
|
|
|
+
|
|
|
+ char strsen[100];
|
|
|
+ socket_->write(strsen,100);
|
|
|
+ socket_->flush();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug("main is not connected.\n");
|
|
|
+ }
|
|
|
+ isConnected_ = true;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::disconnectedSlot()
|
|
|
+{
|
|
|
+// qDebug("connect server fail.");
|
|
|
+ isConnected_ = false;
|
|
|
+ socket_->close();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::readyReadSlot()
|
|
|
+{
|
|
|
+ char * str;
|
|
|
+
|
|
|
+ QByteArray message = socket_->readAll();
|
|
|
+
|
|
|
+ char * strbuff = new char[1000];
|
|
|
+ if((message.size()<1000)&&(message.size()>5))
|
|
|
+ {
|
|
|
+ int nauth;
|
|
|
+ char strdownname[1000];
|
|
|
+ memcpy(&nauth,message.data(),sizeof(int));
|
|
|
+ memcpy(strdownname,message.data()+sizeof(int),(message.size()-sizeof(int)));
|
|
|
+ strdownname[message.size()-sizeof(int)] = 0;
|
|
|
+ if(nauth == 0)
|
|
|
+ {
|
|
|
+ ui->plainTextEdit->setPlainText(strdownname);
|
|
|
+ ui->pushButton_Update->setEnabled(true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strncpy(mstrdownname,strdownname,1000);
|
|
|
+ ui->plainTextEdit->setPlainText("Down File....");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->plainTextEdit->setPlainText("Reply fail.");
|
|
|
+ ui->pushButton_Update->setEnabled(false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ socket_->close();
|
|
|
+// qDebug(message.data());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::errorSlot(QAbstractSocket::SocketError)
|
|
|
+{
|
|
|
+// QMessageBox::information(this, "show", socket_->errorString());
|
|
|
+ disconnectedSlot();
|
|
|
+ ui->plainTextEdit->setPlainText("Connect Server Fail.");
|
|
|
+ ui->pushButton_Update->setEnabled(true);
|
|
|
+}
|
|
|
+
|