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().
This commit is contained in:
Denis Davydov 2018-06-22 15:10:03 +03:00
parent aac8567528
commit 7df934b392
2 changed files with 10 additions and 4 deletions

View File

@ -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!"));
}

View File

@ -32,4 +32,5 @@ class MainWindow : public QMainWindow
Handler *handler;
bool receive;
const QString my_ipv6 = Network::local_ipv6();
};