diff options
Diffstat (limited to 'examples')
19 files changed, 45 insertions, 102 deletions
diff --git a/examples/embedded/flickable/main.cpp b/examples/embedded/flickable/main.cpp index fd30d15e49..139baa6ba7 100644 --- a/examples/embedded/flickable/main.cpp +++ b/examples/embedded/flickable/main.cpp @@ -72,7 +72,7 @@ static QStringList colorPairs(int max) // randomize it colors.clear(); while (combinedColors.count()) { - int i = QRandomGenerator::global()->bounded(int(combinedColors.count())); + int i = QRandomGenerator::global()->bounded(combinedColors.count()); colors << combinedColors[i]; combinedColors.removeAt(i); if (colors.count() == max) diff --git a/examples/examples.pro b/examples/examples.pro index 077e5828a9..fe6c6dc7d4 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -6,7 +6,9 @@ SUBDIRS = \ embedded \ qpa -qtHaveModule(dbus): SUBDIRS += dbus +!contains(TEMPLATE, "vc.*") { # QTBUG-91033 + qtHaveModule(dbus): SUBDIRS += dbus +} qtHaveModule(network): SUBDIRS += network qtHaveModule(testlib): SUBDIRS += qtestlib qtHaveModule(concurrent): SUBDIRS += qtconcurrent diff --git a/examples/network/CMakeLists.txt b/examples/network/CMakeLists.txt index b6ae618d1d..c28c951b69 100644 --- a/examples/network/CMakeLists.txt +++ b/examples/network/CMakeLists.txt @@ -16,7 +16,7 @@ if(TARGET Qt::Widgets) add_subdirectory(loopback) add_subdirectory(threadedfortuneserver) add_subdirectory(googlesuggest) - # add_subdirectory(torrent) FIXME: This does not find its ui file:-/ # special case + add_subdirectory(torrent) add_subdirectory(multicastreceiver) add_subdirectory(multicastsender) add_subdirectory(fortuneclient) 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/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/.prev_CMakeLists.txt b/examples/network/torrent/.prev_CMakeLists.txt deleted file mode 100644 index bc3bf6a465..0000000000 --- a/examples/network/torrent/.prev_CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -# Generated from torrent.pro. - -cmake_minimum_required(VERSION 3.14) -project(torrent LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/torrent") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Network) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(torrent - addtorrentdialog.cpp addtorrentdialog.h - bencodeparser.cpp bencodeparser.h - connectionmanager.cpp connectionmanager.h - filemanager.cpp filemanager.h - forms/addtorrentform.ui - main.cpp - mainwindow.cpp mainwindow.h - metainfo.cpp metainfo.h - peerwireclient.cpp peerwireclient.h - ratecontroller.cpp ratecontroller.h - torrentclient.cpp torrentclient.h - torrentserver.cpp torrentserver.h - trackerclient.cpp trackerclient.h -) -set_target_properties(torrent PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(torrent PUBLIC - Qt::Core - Qt::Gui - Qt::Network - Qt::Widgets -) - - -# Resources: -set(icons_resource_files - "icons/1downarrow.png" - "icons/1uparrow.png" - "icons/bottom.png" - "icons/exit.png" - "icons/peertopeer.png" - "icons/player_pause.png" - "icons/player_play.png" - "icons/player_stop.png" -) - -qt6_add_resources(torrent "icons" - PREFIX - "/" - FILES - ${icons_resource_files} -) - -install(TARGETS torrent - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/network/torrent/CMakeLists.txt b/examples/network/torrent/CMakeLists.txt index 7eea3d02bc..0d1f6735e3 100644 --- a/examples/network/torrent/CMakeLists.txt +++ b/examples/network/torrent/CMakeLists.txt @@ -22,10 +22,10 @@ find_package(Qt6 COMPONENTS Widgets) qt_add_executable(torrent addtorrentdialog.cpp addtorrentdialog.h + addtorrentform.ui bencodeparser.cpp bencodeparser.h connectionmanager.cpp connectionmanager.h filemanager.cpp filemanager.h - forms/addtorrentform.ui main.cpp mainwindow.cpp mainwindow.h metainfo.cpp metainfo.h @@ -39,7 +39,6 @@ set_target_properties(torrent PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_include_directories(torrent PUBLIC forms) # special case target_link_libraries(torrent PUBLIC Qt::Core Qt::Gui diff --git a/examples/network/torrent/forms/addtorrentform.ui b/examples/network/torrent/addtorrentform.ui index 950bb67119..950bb67119 100644 --- a/examples/network/torrent/forms/addtorrentform.ui +++ b/examples/network/torrent/addtorrentform.ui diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp index 129ded3fa4..10a54e7962 100644 --- a/examples/network/torrent/mainwindow.cpp +++ b/examples/network/torrent/mainwindow.cpp @@ -93,7 +93,7 @@ public: progressBarOption.state = QStyle::State_Enabled; progressBarOption.direction = QApplication::layoutDirection(); progressBarOption.rect = option.rect; - progressBarOption.fontMetrics = QApplication::fontMetrics(); + progressBarOption.fontMetrics = QFontMetrics(QApplication::font()); progressBarOption.minimum = 0; progressBarOption.maximum = 100; progressBarOption.textAlignment = Qt::AlignCenter; diff --git a/examples/network/torrent/torrent.pro b/examples/network/torrent/torrent.pro index c640c3b5d0..929c5cb784 100644 --- a/examples/network/torrent/torrent.pro +++ b/examples/network/torrent/torrent.pro @@ -27,7 +27,7 @@ SOURCES += main.cpp \ trackerclient.cpp # Forms and resources -FORMS += forms/addtorrentform.ui +FORMS += addtorrentform.ui RESOURCES += icons.qrc # install 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; diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index cd7e8085a2..7df24e06f6 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -388,8 +388,14 @@ void Dialog::setColor() void Dialog::setFont() { const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value()); + + const QString &description = fontLabel->text(); + QFont defaultFont; + if (!description.isEmpty()) + defaultFont.fromString(description); + bool ok; - QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this, "Select Font", options); + QFont font = QFontDialog::getFont(&ok, defaultFont, this, "Select Font", options); if (ok) { fontLabel->setText(font.key()); fontLabel->setFont(font); diff --git a/examples/widgets/doc/src/addressbook-tutorial.qdoc b/examples/widgets/doc/src/addressbook-tutorial.qdoc index 563b6a2be9..53acb82b1a 100644 --- a/examples/widgets/doc/src/addressbook-tutorial.qdoc +++ b/examples/widgets/doc/src/addressbook-tutorial.qdoc @@ -842,7 +842,7 @@ If \c fileName is not empty, we create a QFile object, \c file, with \c fileName. QFile works with QDataStream as QFile is a QIODevice. - Next, we attempt to open the file in \l{QIODevice::}{WriteOnly} mode. + Next, we attempt to open the file in \l{QIODeviceBase::}{WriteOnly} mode. If this is unsuccessful, we display a QMessageBox to inform the user. \snippet tutorials/addressbook/part6/addressbook.cpp saveToFile() function part2 @@ -869,7 +869,7 @@ \image addressbook-tutorial-part6-load.png If \c fileName is not empty, again, we use a QFile object, \c file, and - attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our + attempt to open it in \l{QIODeviceBase::}{ReadOnly} mode. Similar to our implementation of \c saveToFile(), if this attempt is unsuccessful, we display a QMessageBox to inform the user. @@ -939,7 +939,7 @@ choose a location for the file. Using the file name chosen, we create an instance of QFile to write to. - We attempt to open the file in \l{QIODevice::}{WriteOnly} mode. If this + We attempt to open the file in \l{QIODeviceBase::}{WriteOnly} mode. If this process fails, we display a QMessageBox to inform the user about the problem and return. Otherwise, we pass the file as a parameter to a QTextStream object, \c out. Like QDataStream, the QTextStream class diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp index 20e5d45c95..a7d174a4f4 100644 --- a/examples/widgets/itemviews/dirview/main.cpp +++ b/examples/widgets/itemviews/dirview/main.cpp @@ -76,6 +76,8 @@ int main(int argc, char *argv[]) ? QString() : parser.positionalArguments().first(); QFileSystemModel model; + QFileIconProvider iconProvider; + model.setIconProvider(&iconProvider); model.setRootPath(""); if (parser.isSet(dontUseCustomDirectoryIconsOption)) model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons); diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp index 7faa325469..47fc232751 100644 --- a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp +++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp @@ -62,7 +62,7 @@ MainWindow::MainWindow(QWidget *parent) QFile file(":/default.txt"); file.open(QIODevice::ReadOnly); - TreeModel *model = new TreeModel(headers, file.readAll()); + TreeModel *model = new TreeModel(headers, file.readAll(), this); file.close(); view->setModel(model); diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp index 1161a8b5d2..e8ca2afffd 100644 --- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp +++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp @@ -212,6 +212,9 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent) //! [8] int TreeModel::rowCount(const QModelIndex &parent) const { + if (parent.isValid() && parent.column() > 0) + return 0; + const TreeItem *parentItem = getItem(parent); return parentItem ? parentItem->childCount() : 0; diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp index 2c663a1618..431a804298 100644 --- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp +++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp @@ -264,7 +264,7 @@ void ToolBar::randomize() QList<QAction *> randomized; QList<QAction *> actions = this->actions(); while (!actions.isEmpty()) { - QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(int(actions.size()))); + QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size())); randomized.append(action); } clear(); diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp index 7de0c7c45b..0e333b693f 100644 --- a/examples/widgets/widgets/imageviewer/imageviewer.cpp +++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp @@ -115,8 +115,11 @@ bool ImageViewer::loadFile(const QString &fileName) setWindowFilePath(fileName); - const QString message = tr("Opened \"%1\", %2x%3, Depth: %4") - .arg(QDir::toNativeSeparators(fileName)).arg(image.width()).arg(image.height()).arg(image.depth()); + const QString description = image.colorSpace().isValid() + ? image.colorSpace().description() : tr("unknown"); + const QString message = tr("Opened \"%1\", %2x%3, Depth: %4 (%5)") + .arg(QDir::toNativeSeparators(fileName)).arg(image.width()).arg(image.height()) + .arg(image.depth()).arg(description); statusBar()->showMessage(message); return true; } @@ -176,6 +179,7 @@ static void initializeImageFileDialog(QFileDialog &dialog, QFileDialog::AcceptMo mimeTypeFilters.sort(); dialog.setMimeTypeFilters(mimeTypeFilters); dialog.selectMimeTypeFilter("image/jpeg"); + dialog.setAcceptMode(acceptMode); if (acceptMode == QFileDialog::AcceptSave) dialog.setDefaultSuffix("jpg"); } @@ -185,7 +189,7 @@ void ImageViewer::open() QFileDialog dialog(this, tr("Open File")); initializeImageFileDialog(dialog, QFileDialog::AcceptOpen); - while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {} + while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().constFirst())) {} } //! [1] @@ -194,7 +198,7 @@ void ImageViewer::saveAs() QFileDialog dialog(this, tr("Save File As")); initializeImageFileDialog(dialog, QFileDialog::AcceptSave); - while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().first())) {} + while (dialog.exec() == QDialog::Accepted && !saveFile(dialog.selectedFiles().constFirst())) {} } //! [5] @@ -365,7 +369,7 @@ void ImageViewer::createActions() QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(tr("&About"), this, &ImageViewer::about); - helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt); + helpMenu->addAction(tr("About &Qt"), this, &QApplication::aboutQt); } //! [18] diff --git a/examples/widgets/widgets/imageviewer/main.cpp b/examples/widgets/widgets/imageviewer/main.cpp index 035c769693..fbfaecde45 100644 --- a/examples/widgets/widgets/imageviewer/main.cpp +++ b/examples/widgets/widgets/imageviewer/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) commandLineParser.process(QCoreApplication::arguments()); ImageViewer imageViewer; if (!commandLineParser.positionalArguments().isEmpty() - && !imageViewer.loadFile(commandLineParser.positionalArguments().front())) { + && !imageViewer.loadFile(commandLineParser.positionalArguments().constFirst())) { return -1; } imageViewer.show(); |