I'm building a music player, that checks the status with SqueezePlay, which is a SqueezeBox controller app. To cut a long story short, I'm checking the status of Squeezeplay ever 5 seconds by using threading. If the song title changes, I let it update the labels (Qlabel, album artwork (QPixmap), etc. However, when I ask it to update it via threading, I'm getting It is not safe to use pixmaps outside the GUI thread .
How can I do threading but still set the QPixmap?
Sample code:
#self.sq.getArtwork() returns variable with the image
coverArt = self.sq.getArtwork()
coverPixMap = QtGui.QPixmap()
coverPixMap.loadFromData(coverArt)
self.albumArt.setPixmap(coverPixMap)
Many thanks!
Update: I tried the following with Emit, but it doesn't work, can someone take a look what I'm doing wrong?
def setNewArtwork(self, image):
coverPixMap = QtGui.QPixmap()
coverPixMap.convertFromImage(image)
icon = QtGui.QIcon(coverPixMap)
item.setIcon(icon)
def getNewArtwork(self):
coverArt = self.sq.getArtwork()
icon = QtGui.QImage(coverArt)
self.emit(QtCore.SIGNAL('setNewArtwork(QImage)'), icon)
self.emit(QtCore.SIGNAL('setNewArtwork(QImage)'), icon)
Should this line have QPixmap instead of QImage, since you're using pixmaps? I don't know how hard the types are enforced. Also make sure that you're using a queued connection, if such a concept exist in PyQT. This ensures that the slot is run in the receiver's thread rather than the caller's thread. – Arber