0

I need to call a DBus method with a uint argument. Using message.setArguments([]) sets integers, which results in an error that the function could not be found.

For Qt5, this was already answered here.

In Qt6 with PySide6, this doesn't work unfortunatly. QDBusArgument only has a setVariant() method, with no type specification. There is an __lshift__() method defined for uint here, but since python has no uint type and ctypes.c_uint() doesn't work either, I guess this is just copied documentation from the C++ library.

First I tried using different types: python integers, ctypes.c_uint(), '0x0', b'0x0'. Adding and subtracting 2**32 from my integer also doesn't help.

l0drex
  • 16
  • 4
  • Yes, most of the Qt for Python docs are just automated copies of the C++ ones (I also believe that the example codes are automatically converted in some ways to make it "look like python", but sometimes they just don't make sense); I've never understood the need for that documentation, I feel it a completely useless duplicate that is just confusing for lots of people, not to mention that there are functions that are missing or don't have proper arguments. I suppose you're the one who submitted [this report](https://bugreports.qt.io/browse/PYSIDE-1904), aren't you? – musicamante Oct 26 '22 at 16:20
  • Surely a QVariant is exactly what you need: `t = QMetaType(QMetaType.Type.UInt.value); v = QVariant(50); v.convert(t); v.typeName()` => `'unit'`. See also: [QDBusVariant](https://doc.qt.io/qt-6/qdbusvariant.html). – ekhumoro Oct 26 '22 at 22:04
  • 1
    @ekhumoro But the OP is using PySide, and, as far as I know, they removed QVariant. – musicamante Oct 26 '22 at 22:49
  • 2
    @musicamante Huh. I just now noticed the link in your previous comment. But the OP certainly didn't post that bug report (which is nearly six months old). [Florian Bruhin](https://github.com/The-Compiler) has [this SO account](https://stackoverflow.com/users/2085149/the-compiler). From memory, PyQt made the same mistake with QVariant and had to reintroduce it (but I think for different reasons). – ekhumoro Oct 27 '22 at 02:23
  • 1
    @ekhumoro Shame on me: I was mistaken by the google date based on the latest update, I didn't notice the creation date. I seem to remember the reintroduction of QVariant, their removal was understandable but, as this other issue shows, we cannot live without it, as "costly" it could be. It seems clear that the "Qt for Python" team has to make a choice: either they reintroduce QVariant, or they add support for objects that need strict typing. And, in the way, they could just do other useful things, like fixing/removing those almost useless docs (and that ugly `snake_case` "feature" ;-) )... – musicamante Oct 27 '22 at 02:50
  • 1
    @musicamante It's surprising that they didn't look at all [the prior art](https://www.riverbankcomputing.com/static/Docs/PyQt6/pyqt_qvariant.html) first. Another possibility would be to [temporarily suppress automatic type conversion](https://www.riverbankcomputing.com/static/Docs/PyQt6/api/sip/sip-module.html#PyQt6.sip.enableautoconversion). About the docs: what's really missing is something that details all the significant *differences* between PyQt/PySide and Qt, along with a basic primer for porting C++ examples to Python. Right now, that rather large gap is mostly filled by SO. – ekhumoro Oct 27 '22 at 11:16

0 Answers0