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 & QThread
Forum Updated to NodeBB v4.3 + New Features

QTCPServer & QThread

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.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.
  • C Offline
    C Offline
    Cayan
    wrote on last edited by
    #1

    I've started a thread and I can't connect the signals of the server to it.

    thread.h
    @#include <QtNetwork/QTcpServer>
    #include <QThread>

    class Thread: public QThread
    {
    Q_OBJECT

    public:
    Thread();
    void run();

    private:
    QTcpServer m_server;

    private slots:
    void onReceiveNewConnection();
    };@

    thread.cpp
    @#include "thread.h"

    Thread::Thread()
    {
    start();
    }

    void Thread::run()
    {
    m_server = new QTcpServer();
    connect(m_server, SIGNAL(newConnection()), /this,/ SLOT(onReceiveNewConnection()));
    m_server->listen(QHostAddress::Any, port);
    while(!isFinished())
    {
    //...
    }
    }

    void Thread::onReceiveNewConnection()
    {
    qDebug() << "New connection!";
    }@

    The code never reaches the slot onReceiveNewConnection.
    Could anyone help me to solve this out?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      [quote author="Cayan" date="1324941299"]
      @
      void Thread::run()
      {
      m_server = new QTcpServer();
      connect(m_server, SIGNAL(newConnection()), /this,/ SLOT(onReceiveNewConnection()));
      m_server->listen(QHostAddress::Any, port);
      while(!isFinished())
      {
      //...
      }
      }

      void Proxy::onReceiveNewConnection()
      {
      qDebug() << "New connection!";
      }@
      [/quote]

      You should check the return value of connect, it will indicate false. You are trying to connect to "this" indcating that there you should be a slot called onReceiveConnection in Thread, but it is a slot in Proxy. It is this way at least in your post.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3
        1. That does not even compile
        2. http://developer.qt.nokia.com/wiki/Threads_Events_QObjects

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        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