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 defined a slot when is call is executed on separately Qthread c++?

how to defined a slot when is call is executed on separately Qthread c++?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 675 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.
  • stackprogramerS Offline
    stackprogramerS Offline
    stackprogramer
    wrote on last edited by
    #1

    i want to defined a slot when is called it executed on separately Qthread c++.....
    when two slot are on same thread we observed that signal second is queued and when
    first slot is fished another function slot is executed....

    JonBJ 1 Reply Last reply
    0
    • stackprogramerS stackprogramer

      i want to defined a slot when is called it executed on separately Qthread c++.....
      when two slot are on same thread we observed that signal second is queued and when
      first slot is fished another function slot is executed....

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

      @stackprogramer
      Put the two slots separately in each of the two separate threads you want each one to execute in. I don't know how to answer better than that.

      Don't forget that if you are using multiple threads you cannot/must not do an UI operations in anything other than main UI thread....

      1 Reply Last reply
      0
      • stackprogramerS Offline
        stackprogramerS Offline
        stackprogramer
        wrote on last edited by
        #3

        Finally i used this way. i didn't used subclass as thread i used only a thread and i moved port serial to on it....

            QThread* thread = new QThread;
            serialPort->moveToThread(thread);
            thread->start();
        
        JonBJ 1 Reply Last reply
        0
        • stackprogramerS stackprogramer

          Finally i used this way. i didn't used subclass as thread i used only a thread and i moved port serial to on it....

              QThread* thread = new QThread;
              serialPort->moveToThread(thread);
              thread->start();
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @stackprogramer
          Just to say: of course I do not know what exactly your code does. But people keep introducing threads --- which are complex in Qt --- to do things where Qt's existing asynchronous signal/slot architecture should mean there is no need to do so. When using serial ports I see lots of people start using separate threads to handle blocking serial port calls, when they would be much better using no thread but non-blocking signals like readRead() instead. So I hope you really know what you are doing/have a use case....

          1 Reply Last reply
          1
          • stackprogramerS Offline
            stackprogramerS Offline
            stackprogramer
            wrote on last edited by
            #5

            @JonB said in how to defined a slot when is call is executed on separately Qthread c++?:

            Just to say: of course I do not know what exactly your code does. But people keep introducing threads --- which are complex in Qt --- to do things where Qt's existing asynchronous signal/slot architecture should mean there is no need to do so. When using serial ports I see lots of people start using separate threads to handle blocking serial port calls, when they would be much better using no thread but non-blocking signals like readRead() instead. So I hope you really know what you are doing/have a use case....

            Hi @JonB thanks for attention yes i know your solution but we have should used threads because we should manager 7 serial port and udp....a little delay we have lost

            we should managed timing input and output data

            JonBJ 1 Reply Last reply
            0
            • stackprogramerS stackprogramer

              @JonB said in how to defined a slot when is call is executed on separately Qthread c++?:

              Just to say: of course I do not know what exactly your code does. But people keep introducing threads --- which are complex in Qt --- to do things where Qt's existing asynchronous signal/slot architecture should mean there is no need to do so. When using serial ports I see lots of people start using separate threads to handle blocking serial port calls, when they would be much better using no thread but non-blocking signals like readRead() instead. So I hope you really know what you are doing/have a use case....

              Hi @JonB thanks for attention yes i know your solution but we have should used threads because we should manager 7 serial port and udp....a little delay we have lost

              we should managed timing input and output data

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

              @stackprogramer
              I don't see why it matters whether you are managing 1 serial port or 100 serial ports. I would expect Qt's asynchronous signals/slots to handle this without any need for threads. That's all I can say.

              1 Reply Last reply
              0
              • stackprogramerS Offline
                stackprogramerS Offline
                stackprogramer
                wrote on last edited by
                #7

                @JonB
                we have problems when we write large data on serial port and time writing on port is long time(For large file we have to slab data file and....sending it) and other serial port signals is triggered ..........we observe sending data is not real time and we have delay....because an other slot port is executed but first port serial yet is writing........and finally .....
                we have lag in sending files....

                  serialPort->write(serialDataResponse);
                                        serialPort->waitForBytesWritten(300);
                
                JonBJ 1 Reply Last reply
                0
                • stackprogramerS stackprogramer

                  @JonB
                  we have problems when we write large data on serial port and time writing on port is long time(For large file we have to slab data file and....sending it) and other serial port signals is triggered ..........we observe sending data is not real time and we have delay....because an other slot port is executed but first port serial yet is writing........and finally .....
                  we have lag in sending files....

                    serialPort->write(serialDataResponse);
                                          serialPort->waitForBytesWritten(300);
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @stackprogramer
                  I wouldn't use waitForBytesWritten() either, it's just another blocking call (so it requires a thread), I'd just use the signals. And I don't see it tells you that much about what's really going on anyway.

                  But you know more about your situation than I do. Maybe you do need your threads for some reason.

                  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