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 create Nested QThread( Create one inside another)?
Forum Updated to NodeBB v4.3 + New Features

How to create Nested QThread( Create one inside another)?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.2k 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.
  • brucezcgB Offline
    brucezcgB Offline
    brucezcg
    wrote on last edited by
    #1

    I have One Worker Thead

    void startTcpThread()
    {
    QThread* thread = new QThread;
    connect(thread, SIGNAL (started()), mTcpProcess, SLOT (run()));//Run
    connect(mTcpProcess, SIGNAL (finished()), thread, SLOT (quit()));//Quit thread
    connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater()));//Delete Thread
    mTcpProcess->moveToThread(thread);
    thread->start();
    }

    is it possible to create other thread inside mTcpProcess?

    jsulmJ 1 Reply Last reply
    0
    • brucezcgB brucezcg

      I have One Worker Thead

      void startTcpThread()
      {
      QThread* thread = new QThread;
      connect(thread, SIGNAL (started()), mTcpProcess, SLOT (run()));//Run
      connect(mTcpProcess, SIGNAL (finished()), thread, SLOT (quit()));//Quit thread
      connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater()));//Delete Thread
      mTcpProcess->moveToThread(thread);
      thread->start();
      }

      is it possible to create other thread inside mTcpProcess?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @brucezcg Sure, you can create a thread from another thread. You're already doing this when you create your first thread (it is created from the main thread).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      brucezcgB 1 Reply Last reply
      3
      • jsulmJ jsulm

        @brucezcg Sure, you can create a thread from another thread. You're already doing this when you create your first thread (it is created from the main thread).

        brucezcgB Offline
        brucezcgB Offline
        brucezcg
        wrote on last edited by
        #3

        @jsulm Thanks, and one more question, how to do sleep in function run() which inside my worker class (inherit from QObject)

        jsulmJ J.HilkJ 2 Replies Last reply
        0
        • brucezcgB brucezcg

          @jsulm Thanks, and one more question, how to do sleep in function run() which inside my worker class (inherit from QObject)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @brucezcg http://doc.qt.io/qt-5/qthread.html#sleep

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • brucezcgB brucezcg

            @jsulm Thanks, and one more question, how to do sleep in function run() which inside my worker class (inherit from QObject)

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @brucezcg
            Be carefull with the sleep function, chances are high, that you’re approaching this from the wrong angle.
            Especially if you’re new to Qt’s threading system, which I asume you are, from your questions in this topic.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            brucezcgB 1 Reply Last reply
            3
            • J.HilkJ J.Hilk

              @brucezcg
              Be carefull with the sleep function, chances are high, that you’re approaching this from the wrong angle.
              Especially if you’re new to Qt’s threading system, which I asume you are, from your questions in this topic.

              brucezcgB Offline
              brucezcgB Offline
              brucezcg
              wrote on last edited by
              #6

              @J.Hilk Okay, Thanks

              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