Skip to content
Hlab, lab-197 edited this page Nov 13, 2012 · 1 revision

GUI Tips

qt4reactor:

  • Whenever using twisted (i.e. LabRAD) with PyQt4, qt4reactor.py must be instantiated before twisted. Even 'import LabRAD' must come after qt4reactor. Doing otherwise will result in a "reactor already installed" error.

    if __name__ == "__main__":
        a = QtGui.QApplication( [] )
        import qt4reactor
        qt4reactor.install()
        from twisted.internet import reactor
        histogrammer = Histogrammer(reactor)
        histogrammer.show()
        reactor.run()
  • If integrating PyQt4 with a LabRAD server, make sure to instantiate qt4reactor before importing the server:

    from PyQt4 import QtGui
    a = QtGui.QApplication( [] )
    import qt4reactor
    qt4reactor.install()  
    from labrad.server import LabradServer, setting, Signal
  • Special note: if your LabRAD server inherits from a parent LabRAD server, make sure you import QtGui in the parent server as well!

    from PyQt4 import QtGui
  • Misc: When creating a new window, if the window opens and immediately closes, this is because the window might be assigned to a temporary variable which is deleted as soon as the function finishes. Ex:

    def createWindow(self)
        newWindow = NewWindow(self)

This window will close. If the new window is instantiated as an object of the parent class, then the window will persist.

def createWindow(self)
    self.newWindow = NewWindow(self)