Let Qt handle object deletion.

master
Andrius Štikonas 6 years ago
parent 7efbeab4aa
commit a9e76830c1
  1. 5
      dialog.cpp
  2. 1
      dialog.h
  3. 11
      server.cpp
  4. 1
      server.h
  5. 8
      socket.cpp
  6. 2
      socket.h

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

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

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

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

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

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

Loading…
Cancel
Save