QSignalMapper crashing...

87 views
Skip to first unread message

zoshua

unread,
Oct 24, 2013, 1:08:52 PM10/24/13
to python_in...@googlegroups.com
hey all,

##########################################
my current setup...
os: windows 7 Pro 64
maya: 2014 x64 (version 20130301024-864206)

##########################################
the issue...
running the following code and clicking either of the buttons consistently crashes maya.
the error seems to be an "Unhandled Exception"
i have whittled it down to the issue being the QSignalMapper

##########################################
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Test(QWidget):
    def __init__(self, parent=None):
        super(Test, self).__init__(parent)
        layout = QVBoxLayout() 
        self.b1 = QPushButton("B1")
        self.b2 = QPushButton("B2")
        layout.addWidget(self.b1)
        layout.addWidget(self.b2)
        self.setLayout(layout)
        self.mapper = QSignalMapper(self)
        self.mapper.setMapping(self.b1, "B1")
        self.mapper.setMapping(self.b2, "B2")
        self.b1.clicked.connect(self.mapper.map)
        self.b2.clicked.connect(self.mapper.map)
        self.mapper.mapped[QString].connect(self.sayIt)

    @pyqtSlot(QString)
    def sayIt(self, name):
        print name
        
t = Test()
t.show()
##########################################

anyone have any insight on this one?

Justin Israel

unread,
Oct 24, 2013, 3:43:40 PM10/24/13
to python_in...@googlegroups.com
I can't reproduce it in 2013, using PyQt 4.8.6. Are you sure you have the right match of Qt/PyQt built for 2014?
Also, have you considered switching to PySide, since its bundled with 2014? (unless you have to support backwards compatible PyQt/Maya combinations)

You could work around this problem by not using QSignalMapper at all, and swapping to functools.partial:

from functools import partial
...
        self.b1.clicked.connect(partial(self.sayIt, "B1"))
        self.b2.clicked.connect(partial(self.sayIt, "B2"))

    def sayIt(self, name):
        print name

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/56504c3e-a97d-4bc1-ba51-86c2e674c1a9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

joshua ochoa

unread,
Oct 24, 2013, 5:05:07 PM10/24/13
to python_in...@googlegroups.com
i used the latest win pyqt installer:
 from here:

autodesk docs says 2014 is using Qt4.8.2 

based on the url for the exe i dont really know what version correlates w/ what.
...
my pipeline spider sense is leaning towards your suggestion of the version compatibility being off.

i need to upgrade to Service Pack 1 before going down the build route.

thanks for the code tip but the QSignalMapper is facilitating the need for dynamic button creation based on a list of strings.
here is what that snippet looks like:
##########################################
...
for n in range(len(bttnLabels)):
    bttn = eval( 'QPushButton("%s")' % (QString(bttnLabels[n])) )
    self.mapper.setMapping(bttn,bttnLabels[n])
    bttn.clicked[()].connect(self.mapper.map)
    
    buttonLayout.addWidget(bttn)
                
self.mapper.mapped[QString].connect(self.sayIt)
...
##########################################
let me know if you/anyone might have a little alternative recipe for that.


Justin Israel

unread,
Oct 24, 2013, 6:05:26 PM10/24/13
to python_in...@googlegroups.com
Unfortunately you can't simply grab a precompiled build of PyQt and start using it in Maya. Maya has a custom build of Qt, and your PyQt has to be linked against it, otherwise you can end up with expected problems. Hence the reason people have been hosting PyQt builds for different platforms and Maya versions. So that might be your reason for crashing.
Having PySide now shipped with 2014 definitely makes this all much easier, since you don't have to build anything.

As for your snippet... it seems to be doing a bunch of odd things.
Why are you using eval?
Why looping over length range of the list just to get the list value back out?

When I reduce it to what I think it is doing, I end up with this:

for label in bttnLabels:
    bttn = QPushButton(label)
    self.mapper.setMapping(bttn, label)
    bttn.clicked.connect(self.mapper.map)
    buttonLayout.addWidget(bttn)

... which then can be switched to using partial instead of signal mapper with this:

for label in bttnLabels:
    bttn = QPushButton(label)
    button.clicked.connect(partial(self.sayIt, label))



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

joshua ochoa

unread,
Oct 24, 2013, 6:39:29 PM10/24/13
to python_in...@googlegroups.com
good to know about the custom qt thing. this is the first time ive come across this type of issue dev'ing on windows.
no doubt this approach is definitely due for an upgrade.
i will definitely be looking to convert to pySide in the future.

thanks for taking the time to look into this!
Reply all
Reply to author
Forward
0 new messages