initialize advertiser on the heap

This commit is contained in:
scatterflower 2020-08-23 05:50:37 -05:00
parent 3379557457
commit b186416874
4 changed files with 11 additions and 8 deletions

View File

@ -20,6 +20,7 @@ signals:
public slots: public slots:
void readData(); void readData();
void socketConnected(); void socketConnected();
void socketDisconnected();
private: private:
QString ip; QString ip;

View File

@ -30,5 +30,6 @@ public:
void updateConfig(int current_version); void updateConfig(int current_version);
private: private:
Ui::AkashiMain *ui; Ui::AkashiMain *ui;
Advertiser *advertiser;
}; };
#endif // AKASHIMAIN_H #endif // AKASHIMAIN_H

View File

@ -14,19 +14,16 @@ void Advertiser::contactMasterServer() {
socket = new QTcpSocket(this); socket = new QTcpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(readData())); connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(socket, SIGNAL(connected()), this, SLOT(socketConnected())); connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
socket->connectToHost(ip, port); socket->connectToHost(ip, port);
if(socket->waitForConnected(1000)) {
qDebug("Connected to master server");
} else {
qDebug() << "Master server socket error: " << socket->errorString();
}
} }
void Advertiser::readData() { void Advertiser::readData() {
// The master server should never really send data back to us // The master server should never really send data back to us
// But we handle it anyways, just in case this ever ends up being implemented // But we handle it anyways, just in case this ever ends up being implemented
qDebug() << socket->readAll();
} }
void Advertiser::socketConnected() { void Advertiser::socketConnected() {
@ -43,3 +40,7 @@ void Advertiser::socketConnected() {
socket->flush(); socket->flush();
qDebug("Advertisement sent to master server"); qDebug("Advertisement sent to master server");
} }
void Advertiser::socketDisconnected() {
qDebug("Socket disconnected");
}

View File

@ -29,8 +29,8 @@ AkashiMain::AkashiMain(QWidget *parent)
} else { } else {
if(config.value("advertise", "true").toString() != "true") if(config.value("advertise", "true").toString() != "true")
ws_port = -1; ws_port = -1;
Advertiser advertiser(ms_ip, port, ws_port, local_port, name, description); advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description);
advertiser.contactMasterServer(); advertiser->contactMasterServer();
} }
} }
} }