[PyQt] PyQt4 server trial

Phil Thompson phil at riverbankcomputing.co.uk
Fri May 25 15:51:13 BST 2007


On Friday 25 May 2007 3:22 pm, Uğur Çetin wrote:
> Hi,
>
> I tried to make a simple PyQt4 server that should work without a gui.
> But I think I'm missing some points in this, because the codes I wrote
> simply doesn't work(any connection is refused). Can you tell me where
> the problem is?
>
> content of servertry.py
> -----------------------------
> from PyQt4 import QtCore, QtNetwork
> import sys
>
>
> class MyServer(QtNetwork.QTcpServer):
>     def __init__(self, parent):
>         QtNetwork.QTcpServer.__init__(self, parent)
>         self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any),
> 23105) def incomingConnection(self):
>         print "A connection has come!"
>
> app = QtCore.QCoreApplication(sys.argv)
> server = MyServer(QtCore.QObject())

What's the QObject() in the above line for? You are giving server a parent but 
the parent is being garbage collected immediately, so server's C++ instance 
is being destroyed as a consequence.

Give the parent argument to __init__() and default value of None and don't 
pass an argument to MyServer() and see how that affects things.

Phil



More information about the PyQt mailing list