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. problem of qsocketnotifer in qtcpserver
Forum Updated to NodeBB v4.3 + New Features

problem of qsocketnotifer in qtcpserver

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 912 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.
  • J Offline
    J Offline
    JadeN001
    wrote on last edited by
    #1

    i am designing qtcpserver for sending message from one client to another client for that:
    1.push the all socket(created in myserver class i.e. main thread)into qvector.{in thread 1}
    2.read the data from thread 2.
    3.want to write data also from thread 2.
    the problem is that because i am creating socket in thread 1 and writing by
    clients[i].write("hello"); from thread 2 i am getting notification of

    
    qsocketnotifier socket notifiers cannot be enabled or disabled from another thread 
    

    i know the reason is that i am writing it from thread 2 instead of thread 1.but i want to read and write the data from same thread.
    so Is there any way to define socket in thread2 so i don't get this notification.but i also dont want to create thread eveytime when socket created

    JonBJ 1 Reply Last reply
    0
    • J JadeN001

      i am designing qtcpserver for sending message from one client to another client for that:
      1.push the all socket(created in myserver class i.e. main thread)into qvector.{in thread 1}
      2.read the data from thread 2.
      3.want to write data also from thread 2.
      the problem is that because i am creating socket in thread 1 and writing by
      clients[i].write("hello"); from thread 2 i am getting notification of

      
      qsocketnotifier socket notifiers cannot be enabled or disabled from another thread 
      

      i know the reason is that i am writing it from thread 2 instead of thread 1.but i want to read and write the data from same thread.
      so Is there any way to define socket in thread2 so i don't get this notification.but i also dont want to create thread eveytime when socket created

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @JadeN001
      You do indeed want to do all all socket create/read/writes from same thread.

      So either:

      • do the socket creation in same thread as read/write (probably simplest); or
      • pass messages (signal/slot) between threads; or
      • maybe QObject::moveToThread after creating socket to push to desired read/write thread (I see you have asked about QObject::moveToThread many times)

      ?

      J 1 Reply Last reply
      1
      • JonBJ JonB

        @JadeN001
        You do indeed want to do all all socket create/read/writes from same thread.

        So either:

        • do the socket creation in same thread as read/write (probably simplest); or
        • pass messages (signal/slot) between threads; or
        • maybe QObject::moveToThread after creating socket to push to desired read/write thread (I see you have asked about QObject::moveToThread many times)

        ?

        J Offline
        J Offline
        JadeN001
        wrote on last edited by JadeN001
        #3

        @JonB after creating socket push to desire thread in movetothread , this I have done already.
        But I have created socket (more than one) in main thread and I want to use a separate thread for reading and writing .

        JonBJ 1 Reply Last reply
        0
        • J JadeN001

          @JonB after creating socket push to desire thread in movetothread , this I have done already.
          But I have created socket (more than one) in main thread and I want to use a separate thread for reading and writing .

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @JadeN001
          I believe you have the 3 alternatives I suggested, as per the error message you report.

          Since you have kept the creation thread different from the read/write thread, you have problems.

          If you are already using moveToThread() at some point, I cannot see why you can't move the socket to the correct reading/writing thread.

          J 1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            There were similar / same questions the last days. Please use the search function.
            e.g. https://forum.qt.io/topic/90667/what-is-the-significance-of-qintptr-socket-in-qsocketnotifier-class/15

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            3
            • JonBJ JonB

              @JadeN001
              I believe you have the 3 alternatives I suggested, as per the error message you report.

              Since you have kept the creation thread different from the read/write thread, you have problems.

              If you are already using moveToThread() at some point, I cannot see why you can't move the socket to the correct reading/writing thread.

              J Offline
              J Offline
              JadeN001
              wrote on last edited by
              #6

              @JonB I can move the socket and i can also use for reading and writing.but the socket is created in main thread and so it is registered by qsocketnotifer in main thread and i am using that socket in different thread(read/write thread).
              thats why i am getting notification

              JonBJ 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Why are you trying to do the read and write operations in different threads ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • J JadeN001

                  @JonB I can move the socket and i can also use for reading and writing.but the socket is created in main thread and so it is registered by qsocketnotifer in main thread and i am using that socket in different thread(read/write thread).
                  thats why i am getting notification

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @JadeN001
                  You keep saying that your creation thread is separate from your read/write threads. Since that is what is causing the problem, as @SGaist is asking/suggesting why don't you redesign code so that they are not in different threads? Anyway, answer @SGaist 's question.

                  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