Network chat: default-initialize or direct-initialize members

Where possible

Task-number: QTBUG-108873
Change-Id: I8125ffd63cd0ad1970575fb1a6b85021c03c38d5
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
This commit is contained in:
Mårten Nordheim 2023-05-16 13:17:18 +02:00
parent c437c33f29
commit 3ece5e30b7
5 changed files with 10 additions and 19 deletions

View File

@ -8,8 +8,8 @@
#include <QHostInfo>
Client::Client()
: peerManager(new PeerManager(this))
{
peerManager = new PeerManager(this);
peerManager->setServerPort(server.serverPort());
peerManager->startBroadcasting();

View File

@ -27,12 +27,6 @@ static const int PingInterval = 5 * 1000;
Connection::Connection(QObject *parent)
: QTcpSocket(parent), writer(this)
{
greetingMessage = tr("undefined");
username = tr("unknown");
state = WaitingForGreeting;
currentDataType = Undefined;
transferTimerId = -1;
isGreetingMessageSent = false;
pingTimer.setInterval(PingInterval);
connect(this, &QTcpSocket::readyRead, this,

View File

@ -59,15 +59,15 @@ private:
QCborStreamReader reader;
QCborStreamWriter writer;
QString greetingMessage;
QString username;
QString greetingMessage = tr("undefined");
QString username = tr("unknown");
QTimer pingTimer;
QElapsedTimer pongTime;
QString buffer;
ConnectionState state;
DataType currentDataType;
int transferTimerId;
bool isGreetingMessageSent;
ConnectionState state = WaitingForGreeting;
DataType currentDataType = Undefined;
int transferTimerId = -1;
bool isGreetingMessageSent = false;
};
#endif

View File

@ -12,10 +12,8 @@ static const qint32 BroadcastInterval = 2000;
static const unsigned broadcastPort = 45000;
PeerManager::PeerManager(Client *client)
: QObject(client)
: QObject(client), client(client)
{
this->client = client;
static const char *envVariables[] = {
"USERNAME", "USER", "USERDOMAIN", "HOSTNAME", "DOMAINNAME"
};
@ -30,7 +28,6 @@ PeerManager::PeerManager(Client *client)
username = "unknown";
updateAddresses();
serverPort = 0;
broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
| QUdpSocket::ReuseAddressHint);

View File

@ -35,13 +35,13 @@ private slots:
private:
void updateAddresses();
Client *client;
Client *client = nullptr;
QList<QHostAddress> broadcastAddresses;
QList<QHostAddress> ipAddresses;
QUdpSocket broadcastSocket;
QTimer broadcastTimer;
QString username;
int serverPort;
int serverPort = 0;
};
#endif