From 7df934b3927732e1ad77064ac0ea284eee6a2b56 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 22 Jun 2018 15:10:03 +0300 Subject: [PATCH] Now the basic part of the application works stably. The way of obtaining IPv6 is changed. Also changed the logic of the timer and fixed a bug with multiple calling the slot peerReceiverConnected(). --- src/mainwindow.cpp | 13 +++++++++---- src/mainwindow.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a411dd0..49df6fa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8,6 +8,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); network = new Network(false); handler = new Handler(); + connect(handler, &Handler::createSessionSuccess, this, &MainWindow::peerReceiverConnected); } MainWindow::~MainWindow() @@ -18,19 +19,23 @@ MainWindow::~MainWindow() void MainWindow::on_connectToPeer_clicked() { QJsonObject j; - j["peerID"] = QHostAddress("fc8f:cc50:70b0:3731:d686:a75e:94f2:f44f").toString(); + j["peerID"] = my_ipv6; j["action"] = "createSession"; QString s = ui->peerID->text(); network->sendDatagram(j, s); timer = new QTimer(); - connect(handler, &Handler::createSessionSuccess, this, &MainWindow::peerReceiverConnected); connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm())); timer->start(10000); } void MainWindow::slotTimerAlarm() { - if(!receive) + if(receive) + { + timer->stop(); + receive = false; + } + else { int ret = QMessageBox::critical(this,QObject::tr("Error"),tr("Timeout Error")); timer->stop(); @@ -42,5 +47,5 @@ void MainWindow::slotTimerAlarm() void MainWindow::peerReceiverConnected() { receive = true; - int ret = QMessageBox::information(this,QObject::tr("Info"),tr("Peer available!")); + int ret = QMessageBox::information(this,QObject::tr("Info"),tr("Peer Available!")); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 9973720..278c2b1 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -32,4 +32,5 @@ class MainWindow : public QMainWindow Handler *handler; bool receive; + const QString my_ipv6 = Network::local_ipv6(); };