/tmp/snapshot-pyside-6.2-rel/pyside-setup/examples/dbus/listnames¶
(You can also check this code in the repository)
"""PySide6 port of the QtDBus listnames example from Qt v6.x"""
import sys
from PySide6.QtCore import QCoreApplication
from PySide6.QtDBus import (QDBusConnection, QDBusConnectionInterface,
QDBusInterface, QDBusReply)
def method1():
print("Method 1:")
session_bus = QDBusConnection.sessionBus()
reply = session_bus.interface().registeredServiceNames()
if not reply.isValid():
print("Error:", reply.error().message())
sys.exit(1)
values = reply.value()
for name in values:
print(name)
def method2():
print("Method 2:")
session_bus = QDBusConnection.sessionBus()
dbus_iface = QDBusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", session_bus)
message = dbus_iface.call("ListNames")
reply = QDBusReply(message)
print(reply.value())
def method3():
print("Method 3:")
session_bus = QDBusConnection.sessionBus()
print(session_bus.interface().registeredServiceNames().value())
if __name__ == "__main__":
app = QCoreApplication()
if not QDBusConnection.sessionBus().isConnected():
print("Cannot connect to the D-Bus session bus.\n"
"To start it, run:\n"
"\teval `dbus-launch --auto-syntax`\n",
file=sys.stderr)
sys.exit(1)
method1()
method2()
method3()
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.