[PyQt] How can I throw an exception from python slot and catch it in QtQuick 2 aplication

yellowshl at 163.com yellowshl at 163.com
Mon Jul 3 03:07:51 BST 2017


Hi,I write a python model which is subclass of QabstractListModel and use it in qml. A slot to qml is:


    @pyqtSlot(int,int,QModelIndex,result=bool)
    def removeRows(self,row,count,parent = QModelIndex()):
        ## 1,validate args codes,and call self.beginRemoveRows
        ##  2,remove releated rows by call 3rd library
       ## ##### throw Exception but not work #####
        ## 3,update self.__items and call self.endRemoveRows()
        return True


The slot is defined to return boolean value to the caller.So I can not export any error or exception message to qml layer to make user watch some warnings.
It seems the only way is to throw exception in the slot to make qml caller process specific errors ,But when I throw exception in slot,qml can not receive or catch it.
 I read the page from qt forum: https://forum.qt.io/topic/37157/throwing-qml-exception-from-c-in-qtquick-2-application  but do not get a solution.
Can anyone give me some advice? 
Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170703/2f03456c/attachment.html>


More information about the PyQt mailing list