qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,38 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(multicastreceiver LANGUAGES CXX)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/network/multicastreceiver")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets)
qt_standard_project_setup()
qt_add_executable(multicastreceiver
main.cpp
receiver.cpp receiver.h
)
set_target_properties(multicastreceiver PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(multicastreceiver PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Network
Qt6::Widgets
)
install(TARGETS multicastreceiver
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QApplication>
#include "receiver.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Receiver receiver;
receiver.show();
return app.exec();
}

View File

@ -0,0 +1,11 @@
QT += network widgets
requires(qtConfig(udpsocket))
HEADERS = receiver.h
SOURCES = receiver.cpp \
main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/network/multicastreceiver
INSTALLS += target

View File

@ -0,0 +1,64 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include <QtNetwork>
#include "receiver.h"
Receiver::Receiver(QWidget *parent)
: QDialog(parent),
groupAddress4(QStringLiteral("239.255.43.21")),
groupAddress6(QStringLiteral("ff12::2115"))
{
statusLabel = new QLabel(tr("Listening for multicast messages on both IPv4 and IPv6"));
auto quitButton = new QPushButton(tr("&Quit"));
auto buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
buttonLayout->addWidget(quitButton);
buttonLayout->addStretch(1);
auto mainLayout = new QVBoxLayout;
mainLayout->addWidget(statusLabel);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Multicast Receiver"));
udpSocket4.bind(QHostAddress::AnyIPv4, 45454, QUdpSocket::ShareAddress);
udpSocket4.joinMulticastGroup(groupAddress4);
if (!udpSocket6.bind(QHostAddress::AnyIPv6, 45454, QUdpSocket::ShareAddress) ||
!udpSocket6.joinMulticastGroup(groupAddress6))
statusLabel->setText(tr("Listening for multicast messages on IPv4 only"));
connect(&udpSocket4, &QUdpSocket::readyRead,
this, &Receiver::processPendingDatagrams);
connect(&udpSocket6, &QUdpSocket::readyRead,
this, &Receiver::processPendingDatagrams);
connect(quitButton, &QPushButton::clicked,
qApp, &QCoreApplication::quit);
}
void Receiver::processPendingDatagrams()
{
QByteArray datagram;
// using QUdpSocket::readDatagram (API since Qt 4)
while (udpSocket4.hasPendingDatagrams()) {
datagram.resize(qsizetype(udpSocket4.pendingDatagramSize()));
udpSocket4.readDatagram(datagram.data(), datagram.size());
statusLabel->setText(tr("Received IPv4 datagram: \"%1\"")
.arg(datagram.constData()));
}
// using QUdpSocket::receiveDatagram (API since Qt 5.8)
while (udpSocket6.hasPendingDatagrams()) {
QNetworkDatagram dgram = udpSocket6.receiveDatagram();
statusLabel->setText(statusLabel->text() +
tr("\nReceived IPv6 datagram from [%2]:%3: \"%1\"")
.arg(dgram.data().constData(), dgram.senderAddress().toString())
.arg(dgram.senderPort()));
}
}

View File

@ -0,0 +1,33 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef RECEIVER_H
#define RECEIVER_H
#include <QDialog>
#include <QHostAddress>
#include <QUdpSocket>
QT_BEGIN_NAMESPACE
class QLabel;
QT_END_NAMESPACE
class Receiver : public QDialog
{
Q_OBJECT
public:
explicit Receiver(QWidget *parent = nullptr);
private slots:
void processPendingDatagrams();
private:
QLabel *statusLabel = nullptr;
QUdpSocket udpSocket4;
QUdpSocket udpSocket6;
QHostAddress groupAddress4;
QHostAddress groupAddress6;
};
#endif