0

so I'm building program with 2 classes but when I call function from one class in another class it gives me this error:

QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread

I'm not using QTimer nor QPixmap, here is part of the code:

class Connect(QMainWindow):

    def __init__(self):
            # ...

    def connect(self):
            ip = self.iip.text()
            po = self.ipo.text()
            start_new_thread(self.client, (ip, int(po)))

    def client(self, i, p):
            s = socket(AF_INET, SOCK_STREAM)
            s.connect((i, p))
            data = s.recv(1024)
            Audo().addNewRoom(data)

class Audo(QMainWindow):

    def __init__(self):
            # ...

    def addNewRoom(self, room_name):
        self.rooms[room_name.lower()] = QTreeWidgetItem(self.roomsw, [room_name])
  • You seem to be adding new items (QTreeWidgetItem) in a new thread (which is not the GUI thread). Your code is incomplete so this is an assumption. Remove the `Audo.addNewRoom(...)` from `client` and see if it works that way. – armatita Oct 23 '17 at 08:34
  • I can't remove, I need to add new "room" to Audo class. – AngryPython Oct 23 '17 at 08:37
  • Yes but you don't need to do it in the new thread (or if you do, you should be signaling the GUI thread to do it). But first things first, you need to make the experiment to see if it's that line of code that is causing the problem. – armatita Oct 23 '17 at 08:40
  • Yes, when I remove that line the error doesn't come up, but the problem now is how will I call that function and actually add "room" – AngryPython Oct 23 '17 at 08:48
  • You can make the thread `emit` a signal and have a `connect` method in your Main Window. Check for example the answer to [this question](https://stackoverflow.com/questions/9957195/updating-gui-elements-in-multithreaded-pyqt). – armatita Oct 23 '17 at 08:53

0 Answers0