Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:19:44+00:00 2026-06-13T20:19:44+00:00

Trying to convert a server written in C++ into Python. The server was written

  • 0

Trying to convert a server written in C++ into Python. The server was written to be Asynchronous/Non Blocking. What works in C++ doesn’t seem to want to work for me in Python

I am using PyQT4. I read Python you have to create the event loop or something along those lines any ideas are greatly appreciated

I should mention what seems to not work is that the incomingConnection function in Class Server is never called.

*cheers

import sys
from PyQt4.QtCore import *
from PyQt4.QtNetwork import *


class Client(QObject):
    def __init__(self, parent=None):
        QObject.__init__(self)
        QThreadPool.globalInstance().setMaxThreadCount(15)

    def SetSocket(self, Descriptor):
        self.socket = QTcpSocket(self)
        self.connect(self.socket, SIGNAL("connected()"), SLOT(self.connected()))
        self.connect(self.socket, SIGNAL("disconnected()"), SLOT(self.disconnected()))
        self.connect(self.socket, SIGNAL("readyRead()"), SLOT(self.readyRead()))

        self.socket.setSocketDescriptor(Descriptor)
        print "Client Connected from IP %s" % self.socket.peerAddress().toString()

    def connected(self):
        print "Client Connected Event"

    def disconnected(self):
        print "Client Disconnected"

    def readyRead(self):
        msg = self.socket.readAll()
        print msg


class Server(QObject):
    def __init__(self, parent=None):
        QObject.__init__(self)

    def incomingConnection(self, handle):
        print "incoming"
        self.client = Client(self)
        self.client.SetSocket(handle)

    def StartServer(self):
        self.server = QTcpServer()
        if self.server.listen(QHostAddress("0.0.0.0"), 8888):
            print "Server is awake"    
        else:
            print "Server couldn't wake up"


def main():
    app = QCoreApplication(sys.argv)
    Server().StartServer()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:19:45+00:00Added an answer on June 13, 2026 at 8:19 pm

    incomingConnection is not called because QTcpServer‘s base implementation of the function is called. as incomingConnection is a vitual function, you just have to assign your’s to QTcpServer’s incomingConnection attribute, like this:

    class Server(QObject):
        def __init__(self, parent=None):
            QObject.__init__(self)
    
        def incomingConnection(self, handle):
            print "incoming"
            self.client = Client(self)
            self.client.SetSocket(handle)
    
        def StartServer(self):
            self.server = QTcpServer()
            self.server.incomingConnection = self.incomingConnection
            if self.server.listen(QHostAddress("0.0.0.0"), 8888):
                print "Server is awake"    
            else:
                print "Server couldn't wake up"
    

    you can check out PySide’s documentation, as it’s much more pythonic than PyQt’s, currently hosted only here:
    http://srinikom.github.com/pyside-docs/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a PostgreSQL into SQL Server. But this query doesn't work.
I'm trying to convert a server side Ajax response script into a Django HttpResponse,
I'm trying to convert avi file to flv format using FFMPEG on server, but
I'm trying to convert selenium.py written in python 2. As you see below I
We are trying to convert out old school client server application into a N-Tier
I'm trying to convert MS Access Cross Tab query into SQL Server stored procedure
I'm trying to convert a MS Access query into a SQL Sever stored procedure
I'm trying convert all special chars into HTML safe entities on their way into
i´m using subsonic 3 trying convert a SQL2008 project to MySQL. when the projects
Trying to convert a string of binary inputs into a vector of ints. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.