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. When use QThread ?
Forum Updated to NodeBB v4.3 + New Features

When use QThread ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 2.3k 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.
  • ZoptuneZ Zoptune

    Hi,

    I'm currently working on a project where i have to control a machine.

    I have the DLL that allow me to control that machine but i don't know the proper way to do it.

    I have created a "Machine" class
    Do i have to use QThread ? I'm a bit confused with QThread uses.

    Thx

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    @Zoptune said:

    I have the DLL that allow me to control that machine but i don't know the proper way to do it.

    what does "control" mean?!

    I have created a "Machine" class
    Do i have to use QThread ? I'm a bit confused with QThread uses.

    depends what you want to do.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    ZoptuneZ 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #3

      Hi! If your function calls to that machine interface take too much time then your UI (if you have one) will be unresponsive and the user will be annoyed. In that case better run such calls in another thread of execution. Note that there are multiple ways to do that, using QThread being only one. There's also Qt Concurrent. And the C++ standard library also offers all these things, e.g. std::async.

      ZoptuneZ 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Zoptune said:

        I have the DLL that allow me to control that machine but i don't know the proper way to do it.

        what does "control" mean?!

        I have created a "Machine" class
        Do i have to use QThread ? I'm a bit confused with QThread uses.

        depends what you want to do.

        ZoptuneZ Offline
        ZoptuneZ Offline
        Zoptune
        wrote on last edited by
        #4

        @raven-worx
        "Control" simply mean that i can perform operations like moving the machine, change the motor speed, ...

        I want to use the functions in the DLL and cancel them at any time.

        Sorry if i'm not clear, english is not my mother tongue

        1 Reply Last reply
        0
        • ? A Former User

          Hi! If your function calls to that machine interface take too much time then your UI (if you have one) will be unresponsive and the user will be annoyed. In that case better run such calls in another thread of execution. Note that there are multiple ways to do that, using QThread being only one. There's also Qt Concurrent. And the C++ standard library also offers all these things, e.g. std::async.

          ZoptuneZ Offline
          ZoptuneZ Offline
          Zoptune
          wrote on last edited by
          #5

          @Wieland
          Hi,

          My functions calls do not take so long (about 1sec, maybe 2), but my UI is totaly based on the function return value.

          ? 1 Reply Last reply
          0
          • ZoptuneZ Zoptune

            @Wieland
            Hi,

            My functions calls do not take so long (about 1sec, maybe 2), but my UI is totaly based on the function return value.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            @Zoptune 1 or 2 seconds is too long :)

            ZoptuneZ 1 Reply Last reply
            0
            • ? A Former User

              @Zoptune 1 or 2 seconds is too long :)

              ZoptuneZ Offline
              ZoptuneZ Offline
              Zoptune
              wrote on last edited by
              #7

              @Wieland
              That's what i feared :(
              But my UI don't need any change during these function calls.

              ? 1 Reply Last reply
              0
              • ZoptuneZ Zoptune

                @Wieland
                That's what i feared :(
                But my UI don't need any change during these function calls.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #8

                @Zoptune If you want to avoid complexity then make it visually clear to the user that the UI is frozen on purpose. E.g. disable all controls (buttons etc) and change the cursor to hourglass.

                ZoptuneZ 1 Reply Last reply
                0
                • ? A Former User

                  @Zoptune If you want to avoid complexity then make it visually clear to the user that the UI is frozen on purpose. E.g. disable all controls (buttons etc) and change the cursor to hourglass.

                  ZoptuneZ Offline
                  ZoptuneZ Offline
                  Zoptune
                  wrote on last edited by
                  #9

                  @Wieland
                  Yep, that's what i planned to do :)

                  Last question, Is there any good pratice or tricks about QThread that i need to know ?

                  Thx for help

                  ? 1 Reply Last reply
                  0
                  • ZoptuneZ Zoptune

                    @Wieland
                    Yep, that's what i planned to do :)

                    Last question, Is there any good pratice or tricks about QThread that i need to know ?

                    Thx for help

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #10

                    @Zoptune said:

                    Is there any good pratice or tricks about QThread that i need to know ?

                    Yes. There are many old examples in various places (including legacy official Qt docs) that teach to inherit from QThread. That's just wrong. The newer docs get it right and a good guide can be found here: How To Really, Truly Use QThreads; The Full Explanation.

                    ZoptuneZ 1 Reply Last reply
                    0
                    • ? A Former User

                      @Zoptune said:

                      Is there any good pratice or tricks about QThread that i need to know ?

                      Yes. There are many old examples in various places (including legacy official Qt docs) that teach to inherit from QThread. That's just wrong. The newer docs get it right and a good guide can be found here: How To Really, Truly Use QThreads; The Full Explanation.

                      ZoptuneZ Offline
                      ZoptuneZ Offline
                      Zoptune
                      wrote on last edited by
                      #11

                      @Wieland
                      I red that post 10 min ago ^^

                      Thx for all :)

                      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