Browse Source

Let Qt handle object deletion.

master
Andrius Štikonas 3 years ago
parent
commit
a9e76830c1
6 changed files with 5 additions and 23 deletions
  1. 0
    5
      dialog.cpp
  2. 0
    1
      dialog.h
  3. 3
    8
      server.cpp
  4. 0
    1
      server.h
  5. 1
    7
      socket.cpp
  6. 1
    1
      socket.h

+ 0
- 5
dialog.cpp View File

@@ -33,11 +33,6 @@ Dialog::Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent) :
33 33
     ui->offTimer->setEnabled(false);
34 34
 }
35 35
 
36
-Dialog::~Dialog()
37
-{
38
-    delete ui;
39
-}
40
-
41 36
 void Dialog::updateUi()
42 37
 {
43 38
     for (unsigned int i = 0; i < (*sockets).size(); ++i) {

+ 0
- 1
dialog.h View File

@@ -31,7 +31,6 @@ class Dialog : public QDialog
31 31
 {
32 32
 public:
33 33
     explicit Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent = 0);
34
-    ~Dialog();
35 34
 
36 35
     void discovered();
37 36
     void updateUi();

+ 3
- 8
server.cpp View File

@@ -27,7 +27,7 @@
27 27
 Server::Server(std::vector<Socket*> *sockets_vector)
28 28
 {
29 29
     sockets = sockets_vector;
30
-    udpSocketGet = new QUdpSocket();
30
+    udpSocketGet = new QUdpSocket(this);
31 31
     udpSocketGet->bind(QHostAddress::Any, 10000);
32 32
     connect(udpSocketGet, &QUdpSocket::readyRead, this, &Server::readPendingDatagrams);
33 33
     discoverSockets();
@@ -113,11 +113,6 @@ Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
113 113
     discoverSockets();
114 114
 }
115 115
 
116
-Server::~Server()
117
-{
118
-    delete udpSocketGet;
119
-}
120
-
121 116
 QByteArray Server::listen(QByteArray message)
122 117
 {
123 118
     QByteArray reply;
@@ -185,7 +180,7 @@ void Server::readPendingDatagrams()
185 180
 
186 181
 void Server::discoverSockets()
187 182
 {
188
-    QUdpSocket *udpSocketSend = new QUdpSocket();
183
+    QUdpSocket *udpSocketSend = new QUdpSocket(this);
189 184
     udpSocketSend->connectToHost(QHostAddress::Broadcast, 10000);
190 185
     udpSocketSend->write(discover);
191 186
     udpSocketSend->write(discover);
@@ -235,4 +230,4 @@ QByteArray fives(unsigned short int length)
235 230
     QByteArray packet;
236 231
     packet.fill(0x05, length);
237 232
     return packet;
238
-}
233
+}

+ 0
- 1
server.h View File

@@ -31,7 +31,6 @@ class Server : public QThread
31 31
 public:
32 32
     Server(std::vector<Socket*> *sockets_vector);
33 33
     Server(uint16_t port, QByteArray ssid, QByteArray password);
34
-    ~Server();
35 34
 
36 35
     void discoverSockets();
37 36
     void readPendingDatagrams();

+ 1
- 7
socket.cpp View File

@@ -51,7 +51,7 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply)
51 51
     datagram[PowerOff] = commandIDPower + mac + twenties + zeros + zero;
52 52
     datagram[ReadTable] = commandID[ReadTable] + mac + twenties + /*zeros*/QByteArray::fromHex("00 00 00 00") /*cookie*/ + QByteArray::fromHex("01 00") + zero + zeros;
53 53
 
54
-    udpSocket = new QUdpSocket();
54
+    udpSocket = new QUdpSocket(this);
55 55
     udpSocket->connectToHost(ip, 10000);
56 56
 
57 57
     connect(this, &Socket::datagramQueued, this, &Socket::processQueue);
@@ -64,12 +64,6 @@ Socket::Socket(QHostAddress IPaddress, QByteArray reply)
64 64
     tableData();
65 65
 }
66 66
 
67
-Socket::~Socket()
68
-{
69
-    delete subscribeTimer;
70
-    delete udpSocket;
71
-}
72
-
73 67
 void Socket::sendDatagram(Datagram d)
74 68
 {
75 69
     commands.enqueue(d);

+ 1
- 1
socket.h View File

@@ -39,7 +39,7 @@ Q_SIGNALS:
39 39
 
40 40
 public:
41 41
     Socket(QHostAddress, QByteArray);    // from discovery packet
42
-    ~Socket();
42
+
43 43
     void toggle();
44 44
     void powerOff();
45 45
     void powerOn();

Loading…
Cancel
Save