title: Is it possible to get a list of objects from a PySide2 slot (service call) via QML?
body: <p>I am trying to convert an existing PySide2/QtWidgets application to PySide2/QML. I am trying to get a list of custom objects from a Python service call via a QML <code>MouseArea</code> click.</p>
  
  <p>I currently have a main script (<code>main.py</code>) that launches a <code>QQuickView</code> containing my QML (contained in <code>main.qml</code>). It also registers a custom type for my model (<code>Role</code>, defined in <code>role.py</code>) and exposes an instance of my service class (contained in <code>mock_role_service.py</code>) to the view's root context.</p>
  
  <p>My QML displays correctly and I can click my <code>MouseArea</code>, but instead of getting back <code>List[Role]</code>, I seem to be getting a <code>QVariant</code> tuple. More specifically, <code>QVariant(PySide::PyObjectWrapper, )</code>.</p>
  
  <p>Relevant files:<br>
  <code>mock_role_service.py</code>:  </p>
  
  <pre class="lang-py prettyprint-override"><code>class MockRoleService(QObject):
      def __init__(self):
          super().__init__()
  
          self.next_id = 5
          self.records = {
              1: Role(id_=1,
                      name='Admin'),
              2: Role(id_=2,
                      name='User')
          }
  
      @Slot(result=list)
      def find_all(self) -&gt; List[Role]:
          return list(self.records.values())
  </code></pre>
  
  <p><code>main.py</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>...
  app = QGuiApplication(sys.argv)
  qmlRegisterType(Role, 'Models', 1, 0, 'Role')
  
  view = QQuickView()
  url = QUrl('Views/main.qml')
  view.setSource(url)
  view.setResizeMode(QQuickView.SizeRootObjectToView)
  
  role_service = MockRoleService()
  view.rootContext().setContextProperty("roleService", role_service)
  
  if view.status() == QQuickView.Error:
      sys.exit(-1)
  
  view.show()
  
  sys.exit(app.exec_())
  </code></pre>
  
  <p><code>main.qml</code>:  </p>
  
  <pre><code>...
  MouseArea {
      onClicked: {
          console.log(roleService.find_all())
          for (role in roleService.find_all()) {
              console.log(role.get_id())
          }
      }
  }
  ...
  </code></pre>
  
  <p>The result of the first <code>console.log()</code> call is <code>QVariant(PySide::PyObjectWrapper, )</code> and the for loop is never entered.</p>
  
  <p>I've only been able to find a couple of similar problems online, and the common solution to them so far (like in <a href="https://stackoverflow.com/a/48916427/1631330">this</a> answer) is to set the value to a property of the class and specify it to be of type <code>QVariantList</code>. This is because PySide2 apparently did away with their <code>QVariant</code>-like types, so I can't specify the slot's result type correctly.</p>
  
  <p>However, I'm not sure this solution is appropriate for this situation because I am dealing with a service object. Setting a property on a service class to hold a return value feels brittle. Is there no other way of accomplishing this?</p>