summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/CMakeLists.txt42
-rw-r--r--examples/network/fortuneserver/server.cpp2
-rw-r--r--examples/network/http/CMakeLists.txt10
-rw-r--r--examples/network/http/http.pro4
-rw-r--r--examples/network/http/main.cpp25
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.cpp2
-rw-r--r--examples/network/torrent/torrentclient.cpp16
7 files changed, 37 insertions, 64 deletions
diff --git a/examples/network/CMakeLists.txt b/examples/network/CMakeLists.txt
index c28c951b69..fd61e75aef 100644
--- a/examples/network/CMakeLists.txt
+++ b/examples/network/CMakeLists.txt
@@ -3,36 +3,36 @@
if(NOT TARGET Qt::Network)
return()
endif()
-add_subdirectory(download)
-add_subdirectory(downloadmanager)
+qt_internal_add_example(download)
+qt_internal_add_example(downloadmanager)
if(NOT INTEGRITY)
- add_subdirectory(dnslookup)
+ qt_internal_add_example(dnslookup)
endif()
if(TARGET Qt::Widgets)
- add_subdirectory(blockingfortuneclient)
- add_subdirectory(broadcastreceiver)
- add_subdirectory(broadcastsender)
- add_subdirectory(http)
- add_subdirectory(loopback)
- add_subdirectory(threadedfortuneserver)
- add_subdirectory(googlesuggest)
- add_subdirectory(torrent)
- add_subdirectory(multicastreceiver)
- add_subdirectory(multicastsender)
- add_subdirectory(fortuneclient)
- add_subdirectory(fortuneserver)
+ qt_internal_add_example(blockingfortuneclient)
+ qt_internal_add_example(broadcastreceiver)
+ qt_internal_add_example(broadcastsender)
+ qt_internal_add_example(http)
+ qt_internal_add_example(loopback)
+ qt_internal_add_example(threadedfortuneserver)
+ qt_internal_add_example(googlesuggest)
+ qt_internal_add_example(torrent)
+ qt_internal_add_example(multicastreceiver)
+ qt_internal_add_example(multicastsender)
+ qt_internal_add_example(fortuneclient)
+ qt_internal_add_example(fortuneserver)
endif()
if(QT_FEATURE_processenvironment AND TARGET Qt::Widgets)
- add_subdirectory(network-chat)
+ qt_internal_add_example(network-chat)
endif()
if(QT_FEATURE_ssl AND TARGET Qt::Widgets)
- add_subdirectory(securesocketclient)
+ qt_internal_add_example(securesocketclient)
endif()
if(QT_FEATURE_dtls AND TARGET Qt::Widgets)
- add_subdirectory(secureudpserver)
- add_subdirectory(secureudpclient)
+ qt_internal_add_example(secureudpserver)
+ qt_internal_add_example(secureudpclient)
endif()
if(QT_FEATURE_sctp AND TARGET Qt::Widgets)
- add_subdirectory(multistreamserver)
- add_subdirectory(multistreamclient)
+ qt_internal_add_example(multistreamserver)
+ qt_internal_add_example(multistreamclient)
endif()
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 95aadb60c9..c91b6a5c0c 100644
--- a/examples/network/fortuneserver/server.cpp
+++ b/examples/network/fortuneserver/server.cpp
@@ -145,7 +145,7 @@ void Server::sendFortune()
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_10);
- out << fortunes[QRandomGenerator::global()->bounded(int(fortunes.size()))];
+ out << fortunes[QRandomGenerator::global()->bounded(fortunes.size())];
//! [4] //! [7]
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
diff --git a/examples/network/http/CMakeLists.txt b/examples/network/http/CMakeLists.txt
index b967881c6a..aaa72982fb 100644
--- a/examples/network/http/CMakeLists.txt
+++ b/examples/network/http/CMakeLists.txt
@@ -36,16 +36,6 @@ target_link_libraries(http PUBLIC
Qt::Widgets
)
-if(ANDROID AND TARGET Qt::AndroidExtras)
- target_compile_definitions(http PUBLIC
- REQUEST_PERMISSIONS_ON_ANDROID
- )
-
- target_link_libraries(http PUBLIC
- Qt::AndroidExtras
- )
-endif()
-
install(TARGETS http
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/network/http/http.pro b/examples/network/http/http.pro
index f67cd01495..2f2d3b00ae 100644
--- a/examples/network/http/http.pro
+++ b/examples/network/http/http.pro
@@ -1,8 +1,4 @@
QT += network widgets
-android: qtHaveModule(androidextras) {
- QT += androidextras
- DEFINES += REQUEST_PERMISSIONS_ON_ANDROID
-}
HEADERS += httpwindow.h
SOURCES += httpwindow.cpp \
diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp
index 6c86933fd6..94c3685af8 100644
--- a/examples/network/http/main.cpp
+++ b/examples/network/http/main.cpp
@@ -53,30 +53,17 @@
#include <QScreen>
#include "httpwindow.h"
-#ifdef REQUEST_PERMISSIONS_ON_ANDROID
-#include <QtAndroid>
-
-bool requestStoragePermission() {
- using namespace QtAndroid;
-
- QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE");
- const QHash<QString, PermissionResult> results = requestPermissionsSync(QStringList({permission}));
- if (!results.contains(permission) || results[permission] == PermissionResult::Denied) {
- qWarning() << "Couldn't get permission: " << permission;
- return false;
- }
-
- return true;
-}
-#endif
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
-#ifdef REQUEST_PERMISSIONS_ON_ANDROID
- if (!requestStoragePermission())
+
+ auto permission = QPermission::WriteStorage;
+ if (QCoreApplication::requestPermission(permission).result() != QPermission::Authorized) {
+ qWarning() << "Couldn't get 'WriteStorage' permission!";
return -1;
-#endif
+ }
+
HttpWindow httpWin;
const QRect availableSize = httpWin.screen()->availableGeometry();
httpWin.resize(availableSize.width() / 5, availableSize.height() / 5);
diff --git a/examples/network/threadedfortuneserver/fortuneserver.cpp b/examples/network/threadedfortuneserver/fortuneserver.cpp
index a93bbc7058..73d7e22531 100644
--- a/examples/network/threadedfortuneserver/fortuneserver.cpp
+++ b/examples/network/threadedfortuneserver/fortuneserver.cpp
@@ -72,7 +72,7 @@ FortuneServer::FortuneServer(QObject *parent)
//! [1]
void FortuneServer::incomingConnection(qintptr socketDescriptor)
{
- QString fortune = fortunes.at(QRandomGenerator::global()->bounded(int(fortunes.size())));
+ QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size()));
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
connect(thread, &FortuneThread::finished, thread, &FortuneThread::deleteLater);
thread->start();
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index a63e927e09..7571d77b41 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -700,7 +700,7 @@ void TorrentClient::connectToPeers()
d->connections << client;
// Pick a random peer from the list of weighed peers.
- TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(int(weighedPeers.size())));
+ TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(weighedPeers.size()));
weighedPeers.removeAll(peer);
peer->connectStart = QDateTime::currentSecsSinceEpoch();
peer->lastVisited = peer->connectStart;
@@ -1130,7 +1130,7 @@ void TorrentClient::scheduleUploads()
// random peer to allow it to compete for a position among the
// downloaders. (This is known as an "optimistic unchoke".)
if (!allClients.isEmpty()) {
- PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(int(allClients.size()))];
+ PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(allClients.size())];
if (client->peerWireState() & PeerWireClient::ChokingPeer)
client->unchokePeer();
}
@@ -1191,7 +1191,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
piece = d->payloads.value(client);
if (!piece) {
QList<TorrentPiece *> values = d->pendingPieces.values();
- piece = values.value(QRandomGenerator::global()->bounded(int(values.size())));
+ piece = values.value(QRandomGenerator::global()->bounded(values.size()));
piece->inProgress = true;
d->payloads.insert(client, piece);
}
@@ -1248,7 +1248,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
++it;
}
if (!partialPieces.isEmpty())
- piece = partialPieces.value(QRandomGenerator::global()->bounded(int(partialPieces.size())));
+ piece = partialPieces.value(QRandomGenerator::global()->bounded(partialPieces.size()));
if (!piece) {
// Pick a random piece 3 out of 4 times; otherwise, pick either
@@ -1295,7 +1295,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
}
// Select one piece randomly
- pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(int(piecesReadyForDownload.size())));
+ pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(piecesReadyForDownload.size()));
delete [] occurrences;
} else {
// Make up a list of available piece indices, and pick
@@ -1306,7 +1306,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
if (incompletePiecesAvailableToClient.testBit(i))
values << i;
}
- pieceIndex = values.at(QRandomGenerator::global()->bounded(int(values.size())));
+ pieceIndex = values.at(QRandomGenerator::global()->bounded(values.size()));
}
// Create a new TorrentPiece and fill in all initial
@@ -1398,8 +1398,8 @@ int TorrentClient::requestBlocks(PeerWireClient *client, TorrentPiece *piece, in
// speedup comes from an increased chance of receiving
// different blocks from the different peers.
for (int i = 0; i < bits.size(); ++i) {
- int a = QRandomGenerator::global()->bounded(int(bits.size()));
- int b = QRandomGenerator::global()->bounded(int(bits.size()));
+ int a = QRandomGenerator::global()->bounded(bits.size());
+ int b = QRandomGenerator::global()->bounded(bits.size());
int tmp = bits[a];
bits[a] = bits[b];
bits[b] = tmp;