mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 07:45:30 +08:00
qt 6.5.1 original
This commit is contained in:
41
examples/dbus/pingpong/CMakeLists.txt
Normal file
41
examples/dbus/pingpong/CMakeLists.txt
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(pingpong LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/dbus/pingpong")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core DBus)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(ping
|
||||
ping.cpp
|
||||
ping-common.h
|
||||
)
|
||||
|
||||
target_link_libraries(ping PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::DBus
|
||||
)
|
||||
|
||||
qt_add_executable(pong
|
||||
ping-common.h
|
||||
pong.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(pong PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::DBus
|
||||
)
|
||||
|
||||
install(TARGETS ping pong
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
4
examples/dbus/pingpong/ping-common.h
Normal file
4
examples/dbus/pingpong/ping-common.h
Normal file
@ -0,0 +1,4 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#define SERVICE_NAME "org.example.QtDBus.PingExample"
|
40
examples/dbus/pingpong/ping.cpp
Normal file
40
examples/dbus/pingpong/ping.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "ping-common.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
auto connection = QDBusConnection::sessionBus();
|
||||
|
||||
if (!connection.isConnected()) {
|
||||
qWarning("Cannot connect to the D-Bus session bus.\n"
|
||||
"To start it, run:\n"
|
||||
"\teval `dbus-launch --auto-syntax`\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
QDBusInterface iface(SERVICE_NAME, "/");
|
||||
if (iface.isValid()) {
|
||||
QDBusReply<QString> reply = iface.call("ping", argc > 1 ? argv[1] : "");
|
||||
if (reply.isValid()) {
|
||||
std::cout << "Reply was: " << qPrintable(reply.value()) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
qWarning("Call failed: %s\n", qPrintable(reply.error().message()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
qWarning("%s\n", qPrintable(connection.lastError().message()));
|
||||
return 1;
|
||||
}
|
8
examples/dbus/pingpong/ping.pro
Normal file
8
examples/dbus/pingpong/ping.pro
Normal file
@ -0,0 +1,8 @@
|
||||
QT -= gui
|
||||
QT += dbus
|
||||
|
||||
HEADERS += ping-common.h
|
||||
SOURCES += ping.cpp
|
||||
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/dbus/pingpong
|
||||
INSTALLS += target
|
3
examples/dbus/pingpong/pingpong.pro
Normal file
3
examples/dbus/pingpong/pingpong.pro
Normal file
@ -0,0 +1,3 @@
|
||||
TEMPLATE = subdirs
|
||||
win32:CONFIG += console
|
||||
SUBDIRS = ping.pro pong.pro
|
49
examples/dbus/pingpong/pong.cpp
Normal file
49
examples/dbus/pingpong/pong.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "ping-common.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
|
||||
class Pong : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
QString ping(const QString &arg);
|
||||
};
|
||||
|
||||
QString Pong::ping(const QString &arg)
|
||||
{
|
||||
QMetaObject::invokeMethod(QCoreApplication::instance(), &QCoreApplication::quit);
|
||||
return QString("ping(\"%1\") got called").arg(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
auto connection = QDBusConnection::sessionBus();
|
||||
|
||||
if (!connection.isConnected()) {
|
||||
qWarning("Cannot connect to the D-Bus session bus.\n"
|
||||
"To start it, run:\n"
|
||||
"\teval `dbus-launch --auto-syntax`\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!connection.registerService(SERVICE_NAME)) {
|
||||
qWarning("%s\n", qPrintable(connection.lastError().message()));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Pong pong;
|
||||
connection.registerObject("/", &pong, QDBusConnection::ExportAllSlots);
|
||||
|
||||
app.exec();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "pong.moc"
|
8
examples/dbus/pingpong/pong.pro
Normal file
8
examples/dbus/pingpong/pong.pro
Normal file
@ -0,0 +1,8 @@
|
||||
QT -= gui
|
||||
QT += dbus
|
||||
|
||||
HEADERS += ping-common.h
|
||||
SOURCES += pong.cpp
|
||||
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/dbus/pingpong
|
||||
INSTALLS += target
|
Reference in New Issue
Block a user