From a9e76830c1048ad93a2204538f26f0332f7ea62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 2 Sep 2016 20:56:06 +0100 Subject: [PATCH] Let Qt handle object deletion. --- dialog.cpp | 5 ----- dialog.h | 1 - server.cpp | 11 +++-------- server.h | 1 - socket.cpp | 8 +------- socket.h | 2 +- 6 files changed, 5 insertions(+), 23 deletions(-) diff --git a/dialog.cpp b/dialog.cpp index 6c3de8a..09047ee 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -33,11 +33,6 @@ Dialog::Dialog(std::vector *sockets_vector, QWidget *parent) : ui->offTimer->setEnabled(false); } -Dialog::~Dialog() -{ - delete ui; -} - void Dialog::updateUi() { for (unsigned int i = 0; i < (*sockets).size(); ++i) { diff --git a/dialog.h b/dialog.h index 27828ef..55dc621 100644 --- a/dialog.h +++ b/dialog.h @@ -31,7 +31,6 @@ class Dialog : public QDialog { public: explicit Dialog(std::vector *sockets_vector, QWidget *parent = 0); - ~Dialog(); void discovered(); void updateUi(); diff --git a/server.cpp b/server.cpp index fc38ef1..a940181 100644 --- a/server.cpp +++ b/server.cpp @@ -27,7 +27,7 @@ Server::Server(std::vector *sockets_vector) { sockets = sockets_vector; - udpSocketGet = new QUdpSocket(); + udpSocketGet = new QUdpSocket(this); udpSocketGet->bind(QHostAddress::Any, 10000); connect(udpSocketGet, &QUdpSocket::readyRead, this, &Server::readPendingDatagrams); discoverSockets(); @@ -113,11 +113,6 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password) discoverSockets(); } -Server::~Server() -{ - delete udpSocketGet; -} - QByteArray Server::listen(QByteArray message) { QByteArray reply; @@ -185,7 +180,7 @@ void Server::readPendingDatagrams() void Server::discoverSockets() { - QUdpSocket *udpSocketSend = new QUdpSocket(); + QUdpSocket *udpSocketSend = new QUdpSocket(this); udpSocketSend->connectToHost(QHostAddress::Broadcast, 10000); udpSocketSend->write(discover); udpSocketSend->write(discover); @@ -235,4 +230,4 @@ QByteArray fives(unsigned short int length) QByteArray packet; packet.fill(0x05, length); return packet; -} \ No newline at end of file +} diff --git a/server.h b/server.h index ee448c5..b147e09 100644 --- a/server.h +++ b/server.h @@ -31,7 +31,6 @@ class Server : public QThread public: Server(std::vector *sockets_vector); Server(uint16_t port, QByteArray ssid, QByteArray password); - ~Server(); void discoverSockets(); void readPendingDatagrams(); diff --git a/socket.cpp b/socket.cpp index 8269081..9f7aeb4 100644 --- a/socket.cpp +++ b/socket.cpp @@ -51,7 +51,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply) datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero; datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("00 00 00 00") /*cookie*/ + QByteArray::fromHex("01 00") + zero + zeros; - udpSocket = new QUdpSocket(); + udpSocket = new QUdpSocket(this); udpSocket->connectToHost(ip, 10000); connect(this, &Socket::datagramQueued, this, &Socket::processQueue); @@ -64,12 +64,6 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply) tableData(); } -Socket::~Socket() -{ - delete subscribeTimer; - delete udpSocket; -} - void Socket::sendDatagram(Datagram d) { commands.enqueue(d); diff --git a/socket.h b/socket.h index 06217c3..d533f25 100644 --- a/socket.h +++ b/socket.h @@ -39,7 +39,7 @@ Q_SIGNALS: public: Socket(QHostAddress, QByteArray); // from discovery packet - ~Socket(); + void toggle(); void powerOff(); void powerOn();