Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcpServer in console app don't emit newConnection() signal
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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)?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved