QTcpServer in console app don't emit newConnection() signal



  • I am new both to Qt and networking. I created class inheriting QObject:

    @
    class QwirkleServer:QObject
    {

    Q_OBJECT
    
    public:
    

    ...@

    In class constructor I wrote:

    @
    ...
    server = new QTcpServer(this);
    QHostAddress addr(QString::fromStdString(cd->getIp()));
    server->listen(addr, cd->getPort())

    QObject::connect(server, SIGNAL(​newConnection()), this, SLOT(newPlayerRegistration()));
    @

    The problem is when I try to connect to server via telnet or nc. newConnection() signal is not emited. @server->isListening(); returns true@
    and both
    @server->serverAdress();
    server->serverPort();@
    returns appropriate values.
    I don't block event queue.

    Also is it possible to use Qt networking with pthreads passing QTcpSocket (I have to use pthreads, this is my course assignment)?



  • Hi,

    Just to make sure, how does the main() function look like? You need to have a QCoreApplication:
    @
    int main(...)
    {
    QCoreApplication app(...);
    ...
    return app.exec()
    }
    @

    You can't pass QTcpSocket to another thread. But you can reimplement the protected incomingConnection() function of QTcpServer in a derived class, pass the socket descriptor to another thread and create the QTcpSocket there. I don't know whether the signal-slot connections would work in this case.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.