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) :
ui->offTimer->setEnabled(false);
}

Dialog::~Dialog()
{
delete ui;
}

void Dialog::updateUi()
{
for (unsigned int i = 0; i < (*sockets).size(); ++i) {

+ 0
- 1
dialog.h View File

@@ -31,7 +31,6 @@ class Dialog : public QDialog
{
public:
explicit Dialog(std::vector<Socket*> *sockets_vector, QWidget *parent = 0);
~Dialog();

void discovered();
void updateUi();

+ 3
- 8
server.cpp View File

@@ -27,7 +27,7 @@
Server::Server(std::vector<Socket*> *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;
}
}

+ 0
- 1
server.h View File

@@ -31,7 +31,6 @@ class Server : public QThread
public:
Server(std::vector<Socket*> *sockets_vector);
Server(uint16_t port, QByteArray ssid, QByteArray password);
~Server();

void discoverSockets();
void readPendingDatagrams();

+ 1
- 7
socket.cpp View File

@@ -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);

+ 1
- 1
socket.h View File

@@ -39,7 +39,7 @@ Q_SIGNALS:

public:
Socket(QHostAddress, QByteArray); // from discovery packet
~Socket();
void toggle();
void powerOff();
void powerOn();

Loading…
Cancel
Save