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. how to emit a signal such that only one of the connected slots is triggered?
Qt 6.11 is out! See what's new in the release blog

how to emit a signal such that only one of the connected slots is triggered?

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

    hello, I'm implementing a load balancer for a tcp server.

    when ever I receive a tcp connection request, I pass the file descriptor of the socket to one of the worker threads to handle it. I don't need all worker threads to response to the same socket.

    suppose I have one tcp server object that receives an incoming tcp socket, I have 5 worker QThreads, each has a slot, named handleSocket();

    during initialization, I connected the signal receiveNewSocket() in the tcp server object to the handleSocket() slot of each worker thread.

    so if I simply do emit receiveNewSocket(), all 5 worker threads will be triggered, but I actually only want one to handle the request.

    what should I do?

    I also want to be able to load balance between the worker thread, for example, I want to be able to select one of the 5 threads to handle my request.

    Thanks,

    kshegunovK 1 Reply Last reply
    0
    • B billconan

      hello, I'm implementing a load balancer for a tcp server.

      when ever I receive a tcp connection request, I pass the file descriptor of the socket to one of the worker threads to handle it. I don't need all worker threads to response to the same socket.

      suppose I have one tcp server object that receives an incoming tcp socket, I have 5 worker QThreads, each has a slot, named handleSocket();

      during initialization, I connected the signal receiveNewSocket() in the tcp server object to the handleSocket() slot of each worker thread.

      so if I simply do emit receiveNewSocket(), all 5 worker threads will be triggered, but I actually only want one to handle the request.

      what should I do?

      I also want to be able to load balance between the worker thread, for example, I want to be able to select one of the 5 threads to handle my request.

      Thanks,

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @billconan said in how to emit a signal such that only one of the connected slots is triggered?:

      what should I do?
      I also want to be able to load balance between the worker thread, for example, I want to be able to select one of the 5 threads to handle my request.

      Keep a list of your active threads, and have your load balancing manually (e.g. keep a record of how many requests a thread is currently carrying). Then call the thread directly to handle the new connection - either use QMetaObject::invokeMethod or queue the call with QTimer::singleShot.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3

      • Login

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