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 across threads
Qt 6.11 is out! See what's new in the release blog

QTcpServer across threads

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

    I created a QTcpServer server in the main thread, and connect the readyRead() signal to a worker object in anther thread, however, once I access the server, there will be an warning like that socket notifiers cannot be enabled from another thread, I can't figure out some questions as follows:

    1. Why it happens? from google I know that QTcpSocket must be created and accessed in the same thread, but if so, why did not the official doc point it out, and how am I supposed to know these information so I can dodge these problems.
    2. The only doc I find related has a statement:

    Event driven objects may only be used in a single thread. Specifically, this applies to the timer mechanism and the network module. For example, you cannot start a timer or connect a socket in a thread that is not the object's thread.

    and I don't know what it means by "event driven objects"
    4. I also want to know more about qt multi-thread programming, can you recommend some books or sites(I have already read the docs over and over, but it seems of little help)

    Thank you!

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      from google I know that QTcpSocket must be created and accessed in the same thread

      This is not the case

      Have a look at this example: https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4

      • Login

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