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 moveToThread() works?
Qt 6.11 is out! See what's new in the release blog

How moveToThread() works?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.7k 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.
  • M Offline
    M Offline
    MokJ
    wrote on last edited by
    #1

    can it get called by itself in any way ?
    After I move my object lets call it worker to thread, I connect signals from serverclass to the slots in worker class.
    incommingconnection(qintptr sd){

        QThread *mythread=new QThread();
       WorkerS *worker=new WorkerS(sd);
    
        worker->moveToThread(mythread);
    

    //from here some connections
    emit signal();//this signal too is connected to the slot in worker class
    }

    now in worker class the slot which gets connected to the signal emmited is

    void worker::connectionSocket(sd){

    QTcpSocket *m_socket=new QTcpSocket();
    m_socket->setSocketDescriptor(s)
    }
    so this slot:: connectionSocket(sd) gets executed (number of socket already connected *2)+1 times
    and I really can't figure out why

    VRoninV 1 Reply Last reply
    0
    • M MokJ

      can it get called by itself in any way ?
      After I move my object lets call it worker to thread, I connect signals from serverclass to the slots in worker class.
      incommingconnection(qintptr sd){

          QThread *mythread=new QThread();
         WorkerS *worker=new WorkerS(sd);
      
          worker->moveToThread(mythread);
      

      //from here some connections
      emit signal();//this signal too is connected to the slot in worker class
      }

      now in worker class the slot which gets connected to the signal emmited is

      void worker::connectionSocket(sd){

      QTcpSocket *m_socket=new QTcpSocket();
      m_socket->setSocketDescriptor(s)
      }
      so this slot:: connectionSocket(sd) gets executed (number of socket already connected *2)+1 times
      and I really can't figure out why

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @MokJ said in How moveToThread() works?:

      QTcpSocket *m_socket=

      Very strange to have a local variable with m_ prefix... could you post your entire code?

      "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

      M 1 Reply Last reply
      3
      • VRoninV VRonin

        @MokJ said in How moveToThread() works?:

        QTcpSocket *m_socket=

        Very strange to have a local variable with m_ prefix... could you post your entire code?

        M Offline
        M Offline
        MokJ
        wrote on last edited by MokJ
        #3

        @VRonin
        void server::startserver(){
        it does the starting server things
        }
        incommingconnection(qintptr sd){

        QThread *mythread=new QThread();
        

        WorkerS *worker=new WorkerS(sd);

        worker->moveToThread(mythread);
        

        //from here some connections
        emit connectTheClients();
        }

        worker::worker(qintptr sd,QObject*parent):QObject(parent){
        s=sd;
        }
        void worker::connectionSocket(){

        QTcpSocket *socket=new QTcpSocket();
        socket->setSocketDescriptor(s)
        }

        m_socket , its just a name i've given

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

          Could you post the header file for worker?

          P.S.
          you can use 3 consecutive ` to mark the beginning and the end of a code block, it helps a lot with readability here

          "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
          2
          • M Offline
            M Offline
            MokJ
            wrote on last edited by
            #5

            thanks @VRonin , I've debugged the code and now its working as it should.
            Thanks again @VRonin .

            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