title: How to pass data between Main Widget and QObject that are in different classes
body: <p>My question is, how do I pass data between the server and the QWidget App that is running? E.g., I want to display a new label in the UI that says "Client connected" when the onNewConnection(self) function is being called in MyServer.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>I have the following program structure for the PyQt5 application that uses the Qt Websocket Server:</p>
  
  <pre class="lang-py prettyprint-override"><code>from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QMainWindow, QPushButton, QVBoxLayout, QSystemTrayIcon, QStyle, QMenu, qApp, QAction
  from PyQt5.QtGui import QIcon, QPixmap, QIcon, QFont
  from PyQt5.QtCore import pyqtSlot, Qt, QObject, pyqtSignal
  from PyQt5 import QtWebSockets, QtNetwork
  
  import sys
  
  
  
  
  class App(QWidget):
      def __init__(self, *args, **kwargs):
          super().__init__()
  
          self.title = "Title window"
          self.left = 0
          self.top = 35
          self.width = 550
          self.height = 250
  
      def init_ui(self):
          # Initialise UI elements like buttons, labels, ...
  
  
  class MyServer(QObject):
  
      def __init__(self, parent):
          super(QObject, self).__init__(parent)
          self.clients = []
          self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent)
          if self.server.listen(QtNetwork.QHostAddress.LocalHost, 8765):
              print('Connected: '+self.server.serverName()+' : '+self.server.serverAddress().toString()+':'+str(self.server.serverPort()))
          else:
              print('error')
          self.server.newConnection.connect(self.onNewConnection)
  
          print(self.server.isListening())
  
      def onNewConnection(self):
          print("Connected")
          #self.mySignal.emit("connected")
          self.clientConnection = self.server.nextPendingConnection()
          self.clientConnection.textMessageReceived.connect(self.processTextMessage)
          self.clientConnection.binaryMessageReceived.connect(self.processBinaryMessage)
          self.clientConnection.disconnected.connect(self.socketDisconnected)
  
          self.clients.append(self.clientConnection)
  
      def processTextMessage(self,  message):
          if (self.clientConnection):
              self.clientConnection.sendTextMessage(message)
              print(message)
  
      def processBinaryMessage(self,  message):
          if (self.clientConnection):
              self.clientConnection.sendBinaryMessage(message)
  
      def socketDisconnected(self):
          if (self.clientConnection):
              self.clients.remove(self.clientConnection)
              self.clientConnection.deleteLater()
  
  app = QApplication(sys.argv)
  ex = App()
  serverObject = QtWebSockets.QWebSocketServer('My Socket', QtWebSockets.QWebSocketServer.NonSecureMode)
  server = MyServer(serverObject)
  serverObject.closed.connect(app.quit)
  app.exec_()
  </code></pre>