#!/usr/local/bin/python3
# -*- coding: utf8 -*-
import sys

from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QUrl
from PyQt5.Qt import QObject, pyqtSlot

@pyqtSlot()
def on_cliked():
    print("clicked!")

    # get a dummy property, this works!
    rowcount = tableview.property("rowCount")
    print("rowcount: {}".format(rowcount))

    # TypeError: unable to convert a C++ 'TableViewSelection_QMLTYPE_32*' instance to a Python object
    selection = tableview.property("selection")    


if __name__ == '__main__':
    app = QGuiApplication(sys.argv)

    engine = QQmlApplicationEngine(QUrl("tableview_problem.qml"))
    ctxt = engine.rootContext()
    window = engine.rootObjects()[0]

    tableview = window.findChild(QObject, "tableView")
    if tableview:
        print("found tableview!")
        
    tableview.clicked.connect(on_cliked)

    window.show()

    sys.exit(app.exec_())
