[PyQt] pyqtProperty type error (second try)

s.achterop at rug.nl s.achterop at rug.nl
Fri Nov 1 12:45:52 GMT 2019


Hello list,

I am porting qt5/qtconnectivity/examples/lowenergyscanner to pyqt5.
Bluetooth low energy devices are seached (main.qml) and after selecting a device services are searched (Services.qml).

The port can be found in github <https://github.com/SietseAchterop/BLE_pyqt5> in main.py and the assets directory.

After selecting a device I get the error:
   TypeError: unable to convert a Python 'list' object to a C++ 'QVariant' instance

It seems to be connected with the property
   servicesList = pyqtProperty(QVariant, getServices, notify=servicesUpdated)

The command itself seems ok, but I think this because if I change QVariant to list, the error becomes:
   TypeError: unable to convert a Python 'list' object to a C++ 'QVariantlist' instance

The property is used in Services.qml which is loaded with the loader from main.qml.
The error occurs when the switch is made to Services.qml as far as I can tell.
It still occurs when Services is simplified to:

import QtQuick 2.12
Rectangle {
     width: 300
     height: 600
     ListView {
         id: servicesview
         width: parent.width
         anchors.top: header.bottom
         anchors.bottom: menu.top
         model: device.servicesList
         clip: true

         delegate: Rectangle {
             id: servicebox
             height:100
             width: parent.width
         }
     }
}

Setting the property is ok, but somehow using it in Services.qml gets me the error.
Maybe something to do with the loading?
Note that exactly the same construct is used with searching devices with:
    devicesList = pyqtProperty(QVariant, getDevices, notify=devicesUpdated)
that is used in the ListView in main.qml. And there is no loading there.

   Thanks in advance,
        Sietse


More information about the PyQt mailing list