import sys
from PySide6.QtWidgets import QMainWindow
from PySide6 import QtDBus, QtCore
from PySide6.QtCore import QLibraryInfo, qVersion, Slot
from PySide6.QtWidgets import QApplication, QMainWindow

class MainWindow(QMainWindow):

    def __init__ (self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        service = 'org.freedesktop.DBus'
        path = '/org/freedesktop/DBus'
        iface = 'org.freedesktop.DBus'
        conn = QtDBus.QDBusConnection.systemBus()
        #conn.connect(service, path, iface, "NameOwnerChanged", self.nameownerchangeslot, "nameownerchangeslot")
        #this brings up:
        #TypeError: 'PySide6.QtDBus.QDBusConnection.connect' called with wrong argument types:
        #PySide6.QtDBus.QDBusConnection.connect(str, str, str, str, method, str)
        conn.connect(service, path, iface, "NameOwnerChanged", self, QtCore.SLOT("nameownerchangeslot(QString,QString,QString)"))

    @Slot(str, str, str)
    def nameownerchangeslot(self, arg1:str, arg2:str, arg3:str) -> None:
        print(arg1)
        print(arg2)
        print(arg3)
        pass

if __name__ == '__main__':
    print('Python {}.{}.{} {}'.format(sys.version_info[0], sys.version_info[1],
                                       sys.version_info[2], sys.platform))
    print(QLibraryInfo.build())
    app = QApplication(sys.argv)
    window = MainWindow()
    window.setWindowTitle(qVersion())
    window.resize(800, 480)
    window.show()
    sys.exit(app.exec())
