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

QThread parent issues

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 851 Views 2 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.
  • R Offline
    R Offline
    raketmus
    wrote on last edited by aha_1980
    #1

    Hello, i have a issue rigth now about threads i have a socket thread which own the socket, but when i invoke the send methoed from the gui thread and then call write on the socket i get the following error message.
    (Parent is QNativeSocketEngine(0x26123e4ada0), parent's thread is SocketThread(0x26123e3bda0), current thread is QThread(0x2611f38fde0)
    but i invoked the methoed should the current thread not be socketthread and not qthread?
    How do i fix this?

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

      Hi,

      If you call it directly then no.

      How are you using that code ?

      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
      • R Offline
        R Offline
        raketmus
        wrote on last edited by
        #3

        i call it like so

        QMetaObject::invokeMethod(clients[0], "send", Qt::QueuedConnection, Q_ARG(Message, message2)); 
        

        this from my gui thread, clients[0] is a pointer to the sockethread and send is the send methoed.

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

          Can you show the code where you create your objects and thread ?

          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
          • R raketmus

            i call it like so

            QMetaObject::invokeMethod(clients[0], "send", Qt::QueuedConnection, Q_ARG(Message, message2)); 
            

            this from my gui thread, clients[0] is a pointer to the sockethread and send is the send methoed.

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @raketmus said in QThread parrent issues:

            QMetaObject::invokeMethod(clients[0], "send", Qt::QueuedConnection, Q_ARG(Message, message2)); 
            

            ...clients[0] is a pointer to the sockethread and send is the send methoed.

            The first argument to QMetaObject::invokeMethod() should be an object that lives in the thread. You should pass a pointer to an object that was created inside the thread.

            client[0] manages a thread, but it does not live in that thread. It lives in your GUI thread. Call this to check:

            qDebug() << clients[0];
            qDebug() << clients[0]->thread();
            qDebug() << qApp->thread(); // qApp is your QApplication which lives in the GUI thread
            

            i have a socket thread

            You don't usually need a thread for a socket. Just leave the socket in the GUI thread. Qt socket classes and other communications classes are asynchronous.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            R 1 Reply Last reply
            3
            • JKSHJ JKSH

              @raketmus said in QThread parrent issues:

              QMetaObject::invokeMethod(clients[0], "send", Qt::QueuedConnection, Q_ARG(Message, message2)); 
              

              ...clients[0] is a pointer to the sockethread and send is the send methoed.

              The first argument to QMetaObject::invokeMethod() should be an object that lives in the thread. You should pass a pointer to an object that was created inside the thread.

              client[0] manages a thread, but it does not live in that thread. It lives in your GUI thread. Call this to check:

              qDebug() << clients[0];
              qDebug() << clients[0]->thread();
              qDebug() << qApp->thread(); // qApp is your QApplication which lives in the GUI thread
              

              i have a socket thread

              You don't usually need a thread for a socket. Just leave the socket in the GUI thread. Qt socket classes and other communications classes are asynchronous.

              R Offline
              R Offline
              raketmus
              wrote on last edited by
              #6

              @JKSH
              Here is the output of the debugging it.

              SocketThread(0x1d02b90b3d0)
              QThread(0x1d02b870250)
              QThread(0x1d02b870250)
              

              It would see they all have the same id.

              You don't usually need a thread for a socket. Just leave the socket in the GUI thread. Qt socket classes and other communications classes are asynchronous.

              i am running a server and i would like to use blocking since that is how i set my sockets up.
              but i am not sure how you want me to call it if not like i am doing right now.

              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