mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 07:45:30 +08:00
qt 6.6.0 clean
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
static std::optional<QDnsLookup::Type> typeFromParameter(QStringView type)
|
||||
{
|
||||
if (type.compare(u"a", Qt::CaseInsensitive) == 0)
|
||||
@ -218,7 +219,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
DnsManager manager;
|
||||
manager.setQuery(query);
|
||||
QTimer::singleShot(0, &manager, SLOT(execute()));
|
||||
QTimer::singleShot(0, &manager, &DnsManager::execute);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -3,8 +3,10 @@
|
||||
|
||||
/*!
|
||||
\example network-chat
|
||||
\title Network Chat Example
|
||||
\title Network Chat
|
||||
\ingroup examples-network
|
||||
\examplecategory {Networking}
|
||||
\meta tag {network,serialization}
|
||||
\brief Demonstrates a stateful peer-to-peer Chat client.
|
||||
|
||||
This example uses broadcasting with QUdpSocket and QNetworkInterface to
|
||||
|
@ -28,6 +28,10 @@ set_target_properties(network-chat PROPERTIES
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_compile_definitions(network-chat PRIVATE
|
||||
QT_USE_QSTRINGBUILDER
|
||||
)
|
||||
|
||||
target_link_libraries(network-chat PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
|
@ -1,10 +1,14 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "chatdialog.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QScrollBar>
|
||||
#include <QLineEdit>
|
||||
#include <QTextTable>
|
||||
#include <QMessageBox>
|
||||
|
||||
ChatDialog::ChatDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
@ -27,7 +31,7 @@ ChatDialog::ChatDialog(QWidget *parent)
|
||||
myNickName = client.nickName();
|
||||
newParticipant(myNickName);
|
||||
tableFormat.setBorder(0);
|
||||
QTimer::singleShot(10 * 1000, this, SLOT(showInformation()));
|
||||
QTimer::singleShot(10 * 1000, this, &ChatDialog::showInformation);
|
||||
}
|
||||
|
||||
void ChatDialog::appendMessage(const QString &from, const QString &message)
|
||||
|
@ -12,7 +12,7 @@ class ChatDialog : public QDialog, private Ui::ChatDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatDialog(QWidget *parent = nullptr);
|
||||
explicit ChatDialog(QWidget *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void appendMessage(const QString &from, const QString &message);
|
||||
|
@ -1,15 +1,18 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtNetwork>
|
||||
|
||||
#include "client.h"
|
||||
#include "connection.h"
|
||||
#include "peermanager.h"
|
||||
|
||||
#include <QHostInfo>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
Client::Client()
|
||||
: peerManager(new PeerManager(this))
|
||||
{
|
||||
peerManager = new PeerManager(this);
|
||||
peerManager->setServerPort(server.serverPort());
|
||||
peerManager->startBroadcasting();
|
||||
|
||||
@ -36,14 +39,15 @@ QString Client::nickName() const
|
||||
|
||||
bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
|
||||
{
|
||||
if (senderPort == -1)
|
||||
return peers.contains(senderIp);
|
||||
|
||||
if (!peers.contains(senderIp))
|
||||
auto [begin, end] = peers.equal_range(senderIp);
|
||||
if (begin == peers.constEnd())
|
||||
return false;
|
||||
|
||||
const QList<Connection *> connections = peers.values(senderIp);
|
||||
for (const Connection *connection : connections) {
|
||||
if (senderPort == -1)
|
||||
return true;
|
||||
|
||||
for (; begin != end; ++begin) {
|
||||
Connection *connection = *begin;
|
||||
if (connection->peerPort() == senderPort)
|
||||
return true;
|
||||
}
|
||||
@ -63,8 +67,7 @@ void Client::newConnection(Connection *connection)
|
||||
void Client::readyForUse()
|
||||
{
|
||||
Connection *connection = qobject_cast<Connection *>(sender());
|
||||
if (!connection || hasConnection(connection->peerAddress(),
|
||||
connection->peerPort()))
|
||||
if (!connection || hasConnection(connection->peerAddress(), connection->peerPort()))
|
||||
return;
|
||||
|
||||
connect(connection, &Connection::newMessage,
|
||||
@ -90,8 +93,7 @@ void Client::connectionError(QAbstractSocket::SocketError /* socketError */)
|
||||
|
||||
void Client::removeConnection(Connection *connection)
|
||||
{
|
||||
if (peers.contains(connection->peerAddress())) {
|
||||
peers.remove(connection->peerAddress());
|
||||
if (peers.remove(connection->peerAddress(), connection) > 0) {
|
||||
QString nick = connection->name();
|
||||
if (!nick.isEmpty())
|
||||
emit participantLeft(nick);
|
||||
|
@ -4,12 +4,12 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "server.h"
|
||||
|
||||
#include <QAbstractSocket>
|
||||
#include <QHash>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include "server.h"
|
||||
|
||||
class PeerManager;
|
||||
|
||||
class Client : public QObject
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
#include <QtNetwork>
|
||||
#include <QTimerEvent>
|
||||
|
||||
static const int TransferTimeout = 30 * 1000;
|
||||
static const int PongTimeout = 60 * 1000;
|
||||
@ -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,
|
||||
|
@ -32,8 +32,8 @@ public:
|
||||
Undefined
|
||||
};
|
||||
|
||||
Connection(QObject *parent = nullptr);
|
||||
Connection(qintptr socketDescriptor, QObject *parent = nullptr);
|
||||
explicit Connection(QObject *parent = nullptr);
|
||||
explicit Connection(qintptr socketDescriptor, QObject *parent = nullptr);
|
||||
~Connection();
|
||||
|
||||
QString name() const;
|
||||
@ -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
|
||||
|
@ -1,11 +1,9 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "chatdialog.h"
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ SOURCES = chatdialog.cpp \
|
||||
server.cpp
|
||||
FORMS = chatdialog.ui
|
||||
QT += network widgets
|
||||
DEFINES += QT_USE_QSTRINGBUILDER
|
||||
requires(qtConfig(udpsocket))
|
||||
requires(qtConfig(listwidget))
|
||||
|
||||
|
@ -2,20 +2,18 @@
|
||||
// Copyright (C) 2018 Intel Corporation.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtNetwork>
|
||||
|
||||
#include "client.h"
|
||||
#include "connection.h"
|
||||
#include "peermanager.h"
|
||||
|
||||
#include <QNetworkInterface>
|
||||
|
||||
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);
|
||||
@ -59,11 +56,7 @@ void PeerManager::startBroadcasting()
|
||||
|
||||
bool PeerManager::isLocalHostAddress(const QHostAddress &address) const
|
||||
{
|
||||
for (const QHostAddress &localAddress : ipAddresses) {
|
||||
if (address.isEqual(localAddress))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ipAddresses.contains(address);
|
||||
}
|
||||
|
||||
void PeerManager::sendBroadcastDatagram()
|
||||
@ -79,8 +72,7 @@ void PeerManager::sendBroadcastDatagram()
|
||||
|
||||
bool validBroadcastAddresses = true;
|
||||
for (const QHostAddress &address : std::as_const(broadcastAddresses)) {
|
||||
if (broadcastSocket.writeDatagram(datagram, address,
|
||||
broadcastPort) == -1)
|
||||
if (broadcastSocket.writeDatagram(datagram, address, broadcastPort) == -1)
|
||||
validBroadcastAddresses = false;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class PeerManager : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PeerManager(Client *client);
|
||||
explicit PeerManager(Client *client);
|
||||
|
||||
void setServerPort(int port);
|
||||
QString userName() const;
|
||||
@ -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
|
||||
|
@ -1,8 +1,6 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtNetwork>
|
||||
|
||||
#include "connection.h"
|
||||
#include "server.h"
|
||||
|
||||
|
@ -13,7 +13,7 @@ class Server : public QTcpServer
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Server(QObject *parent = nullptr);
|
||||
explicit Server(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void newConnection(Connection *connection);
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
||||
|
||||
/*!
|
||||
\example rsslisting
|
||||
\example serialization/rsslisting
|
||||
\examplecategory {Networking}
|
||||
\meta tag {serialization}
|
||||
\title A minimal RSS listing application
|
||||
@ -31,11 +31,11 @@
|
||||
former. For the sake of illustration, it gives the widget the Qt blog's URL
|
||||
as default value for the resource to check.
|
||||
|
||||
\snippet rsslisting/main.cpp 0
|
||||
\snippet serialization/rsslisting/main.cpp 0
|
||||
|
||||
\section1 The RSSListing class
|
||||
|
||||
\snippet rsslisting/rsslisting.h 0
|
||||
\snippet serialization/rsslisting/rsslisting.h 0
|
||||
|
||||
The widget itself provides a simple user interface for specifying the URL to
|
||||
fetch and, once available updates are displayed, controlling the downloading
|
||||
@ -51,7 +51,7 @@
|
||||
|
||||
\section2 Construction
|
||||
|
||||
\snippet rsslisting/rsslisting.cpp setup
|
||||
\snippet serialization/rsslisting/rsslisting.cpp setup
|
||||
|
||||
The constructor sets up the assorted components of the widget and connects
|
||||
their various signals to the slots it shall use to handle them.
|
||||
@ -69,7 +69,7 @@
|
||||
|
||||
\section2 The slots
|
||||
|
||||
\snippet rsslisting/rsslisting.cpp slots
|
||||
\snippet serialization/rsslisting/rsslisting.cpp slots
|
||||
|
||||
All slots are kept simple by delegating any hard work to private methods.
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
|
||||
\section2 The get() method
|
||||
|
||||
\snippet rsslisting/rsslisting.cpp get
|
||||
\snippet serialization/rsslisting/rsslisting.cpp get
|
||||
|
||||
The private \c get() method is used by the \c fetch() slot to initiate an
|
||||
HTTP GET request. It first clears the XML stream reader and, if a reply is
|
||||
@ -106,7 +106,7 @@
|
||||
|
||||
\section2 The parseXml() method
|
||||
|
||||
\snippet rsslisting/rsslisting.cpp parse
|
||||
\snippet serialization/rsslisting/rsslisting.cpp parse
|
||||
|
||||
When data is received, and thus made available to the XML stream reader, \c
|
||||
parseXml() reads from the XML stream, checking for \c item elements and,
|
||||
|
@ -83,7 +83,7 @@ void MainWindow::on_connectButton_clicked()
|
||||
return startNewConnection(remoteAddress);
|
||||
|
||||
addInfoMessage(tr("Looking up the host ..."));
|
||||
lookupId = QHostInfo::lookupHost(hostName, this, SLOT(lookupFinished(QHostInfo)));
|
||||
lookupId = QHostInfo::lookupHost(hostName, this, &MainWindow::lookupFinished);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ void RateController::scheduleTransfer()
|
||||
if (transferScheduled)
|
||||
return;
|
||||
transferScheduled = true;
|
||||
QTimer::singleShot(50, this, SLOT(transfer()));
|
||||
QTimer::singleShot(50, this, &RateController::transfer);
|
||||
}
|
||||
|
||||
void RateController::transfer()
|
||||
|
@ -20,7 +20,7 @@ TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
|
||||
void TrackerClient::start(const MetaInfo &info)
|
||||
{
|
||||
metaInfo = info;
|
||||
QTimer::singleShot(0, this, SLOT(fetchPeerList()));
|
||||
QTimer::singleShot(0, this, &TrackerClient::fetchPeerList);
|
||||
|
||||
if (metaInfo.fileForm() == MetaInfo::SingleFileForm) {
|
||||
length = metaInfo.singleFile().length;
|
||||
|
Reference in New Issue
Block a user