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 a new thread in Qt?
Forum Updated to NodeBB v4.3 + New Features

how to create a new thread in Qt?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k Views 3 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    what is the normal way to create a new thread? (i want sth like ::CreateThread in window)

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      The documentation is your friend.
      Also, if you just want to start some function asynchronously, you can take a look at QtConcurrent::run(...).

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        QtConcurrent::run....what is it advantage?
        and can i send a member func to it? eg. Mainwindow:func()...
        or is it better to use a global func to send to it?

        and what should i do when the app quit or close?

        how should i stop it if i want?

        JKSHJ 1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu2
          wrote on last edited by opengpu2
          #4

          can i write like this?
          QtConcurrent::run(func, p);

          before the main()
          @
          void func(pointer* p)
          {
          Class* xxx = new Class();
          while (p->Running())
          {
          xxx->tick();
          }
          delete xxx;
          return;
          }
          @

          when my app is closed, i set the global p make the p->Running()==false in the mainthread.........does this work???

          //ps. can func have return value? does it make sense?

          1 Reply Last reply
          0
          • O opengpu2

            QtConcurrent::run....what is it advantage?
            and can i send a member func to it? eg. Mainwindow:func()...
            or is it better to use a global func to send to it?

            and what should i do when the app quit or close?

            how should i stop it if i want?

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

            @opengpu2 said:

            QtConcurrent::run....what is it advantage?

            There are a few different ways to use threads in Qt. This page tries to explain how to choose: http://doc.qt.io/qt-5/threads-technologies.html

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

            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