PyQt Crash in Maya signal : currentChanged(QModelIndex, QModelIndex)

Hello,
I’ve been working on a PyQt application for Maya and Motionbuilder and recently ran into a crash in Maya.

I don’t know if it’s in my implementation, or possibly a bug with the version of PyQt/SIP I’m running.

I can recreate it with the code found in Part 7 of Yasin Uludag’s great PyQt abstract model tutorials: http://www.yasinuludag.com/blog/?p=98

Once running in Maya, I get a crash whenever I click on an item in the list view and the currentChanged(QModelIndex, QModelIndex) signal is called in the Contollers code. It’s an instant crash, so no errors are printed of any use.

Any suggestions on how debug this? I’m going to try to make a minimal version of the code to reproduce this in a simple single script in the meantime.

Thanks!
-Andrew

Here’s the minimal code to see this crash:


#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore, uic
import maya.OpenMayaUI as OpenMayaUI

import sip
import sys

def getPyQtMayaWindow():
    accessMainWindow = OpenMayaUI.MQtUtil.mainWindow()
    return sip.wrapinstance(long(accessMainWindow), QtCore.QObject)

class pyQtMayaWindow(QtGui.QMainWindow):
    # My custom window, which i want to parent to the maya main window
    def __init__(self, parent=getPyQtMayaWindow()):
        # Init my main window, and pass in the maya main window as it's parent
        QtGui.QMainWindow.__init__(self, parent)
        self.setWindowTitle('My PyQt Window')


def updateDataChanged(id1, id2):
    print 'updateDataChanged'
    print id1
    print id2


if __name__ == '__main__':

    app = pyQtMayaWindow()

    # DATA
    data = QtCore.QStringList()
    data << 'one' << 'two' << 'three' << 'four' << 'five'

    listView = QtGui.QListView()
    listView.show()

    model = QtGui.QStringListModel(data)
    # proxyModel = QtGui.QSortFilterProxyModel()
    # proxyModel.setSourceModel(model)

    listView.setModel(model)
    # print listView.selectionModel()
    QtCore.QObject.connect(listView.selectionModel(), QtCore.SIGNAL('currentChanged(QModelIndex, QModelIndex)'), updateDataChanged)

Those are usually to do with invalid indexes being passed around and qt doesnt handle it gracefully. This is how i’ve done it, using the v2 connection method:


if __name__ == '__main__':

    app = pyQtMayaWindow()

    listView = QtGui.QListView()

    model = QtGui.QStringListModel(['one', 'two', 'three', 'four', 'five'])

    listView.setModel(model)

    listView.selectionModel().currentChanged.connect(updateDataChaged)

    listView.show()

See if you get any further with that

I think I ran into the same issue, and it went away once I was working out of a module and not doing the name == ‘main’ style of starting it. Like: import my_ui as stuff, temp_obj = stuff.the_program(), temp_obj.show()

Thanks for looking into this!

Jason Parks was kind enough to run the code in his environment and didn’t produce a crash. (Also thanks to Randall Hess!)

So I just updated to newer compile of PyQt and that solved the problem.

Thanks!

-Andrew