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. multi-process
QtWS25 Last Chance

multi-process

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 4.9k 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.
  • S Offline
    S Offline
    s002wjh
    wrote on 2 May 2018, 14:06 last edited by
    #1

    is Qprocess class can be use for multi-process? if not what QT class is used to run multiple process.

    K 1 Reply Last reply 2 May 2018, 14:10
    0
    • S s002wjh
      2 May 2018, 14:06

      is Qprocess class can be use for multi-process? if not what QT class is used to run multiple process.

      K Offline
      K Offline
      koahnig
      wrote on 2 May 2018, 14:10 last edited by
      #2

      @s002wjh

      QProcess can be used to start several external processes in parallel.

      For multi-threading check out threads-technologies.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      4
      • S Offline
        S Offline
        s002wjh
        wrote on 2 May 2018, 15:00 last edited by s002wjh 5 Feb 2018, 15:04
        #3

        i plan not to use multi-thread as it require alot change, since all my class are qwidget(so i basically has to identify which function is pixel ploting which function are background that can be move to qobject class etc).

        so i plan to separate the program into smaller program and run in multi-process environment. Anyone done this before?

        also whats different between qtconcurrent vs multi-thread

        K 1 Reply Last reply 2 May 2018, 15:40
        0
        • S s002wjh
          2 May 2018, 15:00

          i plan not to use multi-thread as it require alot change, since all my class are qwidget(so i basically has to identify which function is pixel ploting which function are background that can be move to qobject class etc).

          so i plan to separate the program into smaller program and run in multi-process environment. Anyone done this before?

          also whats different between qtconcurrent vs multi-thread

          K Offline
          K Offline
          koahnig
          wrote on 2 May 2018, 15:40 last edited by koahnig 5 Feb 2018, 19:03
          #4

          @s002wjh

          It is certainly your decision, but think twice.

          Since you would start with QProcess completely independent processes (e.g. *.exe under windows), you have to make sure that all the required settings, parameters and other data is communicated to those processes. If there are just a few things, that might be easy.

          Probably QtConcurrent is a good start for some light-weight multi-threading. At least I felt that way. Check out the qtconcurrent-runfunction-example

          Vote the answer(s) that helped you to solve your issue(s)

          S 1 Reply Last reply 2 May 2018, 18:15
          2
          • K koahnig
            2 May 2018, 15:40

            @s002wjh

            It is certainly your decision, but think twice.

            Since you would start with QProcess completely independent processes (e.g. *.exe under windows), you have to make sure that all the required settings, parameters and other data is communicated to those processes. If there are just a few things, that might be easy.

            Probably QtConcurrent is a good start for some light-weight multi-threading. At least I felt that way. Check out the qtconcurrent-runfunction-example

            S Offline
            S Offline
            s002wjh
            wrote on 2 May 2018, 18:15 last edited by
            #5

            @koahnig
            thanks, ill take look at qtconcurrent, but is it same as QThread, which require Qobject to use movetothread? my only complain with Qthread is all my class are Qwidget, so if i want to do multithread i need look at all the function in Qwidget convert those into Qobject class, which is time consuming just for multithread. So i like to know if there are other method for parrallel computing.

            K 1 Reply Last reply 2 May 2018, 18:50
            0
            • S s002wjh
              2 May 2018, 18:15

              @koahnig
              thanks, ill take look at qtconcurrent, but is it same as QThread, which require Qobject to use movetothread? my only complain with Qthread is all my class are Qwidget, so if i want to do multithread i need look at all the function in Qwidget convert those into Qobject class, which is time consuming just for multithread. So i like to know if there are other method for parrallel computing.

              K Offline
              K Offline
              koahnig
              wrote on 2 May 2018, 18:50 last edited by
              #6

              @s002wjh

              You might want to rethink your concept.

              With QtConcurrent you are not required to do a moveToThread. In my first attempt qith QtConcurrent, I have simply used some global function which was started several times in parallel. Best is really to check out the examples.

              If you cannot use moveToThread because of QWidget, how did you think to use different apps with QProcess?
              Just for clarity QProcess is similar to a new command prompt, but you start something directly.

              Vote the answer(s) that helped you to solve your issue(s)

              S 1 Reply Last reply 2 May 2018, 18:53
              1
              • K koahnig
                2 May 2018, 18:50

                @s002wjh

                You might want to rethink your concept.

                With QtConcurrent you are not required to do a moveToThread. In my first attempt qith QtConcurrent, I have simply used some global function which was started several times in parallel. Best is really to check out the examples.

                If you cannot use moveToThread because of QWidget, how did you think to use different apps with QProcess?
                Just for clarity QProcess is similar to a new command prompt, but you start something directly.

                S Offline
                S Offline
                s002wjh
                wrote on 2 May 2018, 18:53 last edited by s002wjh 5 Feb 2018, 18:56
                #7

                @koahnig
                as i understand Qprocess start an external program, i can say separate my various Qwidget into individual smaller program, the only thing is not sure how to share data in between process.

                i couldn't find good example of qprocess or qtconcurrent, most are simple explainition not good examples. if anyway have link on some good examples let me know

                J 1 Reply Last reply 2 May 2018, 18:58
                0
                • S s002wjh
                  2 May 2018, 18:53

                  @koahnig
                  as i understand Qprocess start an external program, i can say separate my various Qwidget into individual smaller program, the only thing is not sure how to share data in between process.

                  i couldn't find good example of qprocess or qtconcurrent, most are simple explainition not good examples. if anyway have link on some good examples let me know

                  J Online
                  J Online
                  JonB
                  wrote on 2 May 2018, 18:58 last edited by JonB 5 Feb 2018, 19:14
                  #8

                  @s002wjh said in multi-process:

                  @koahnig
                  as i understand Qprocess start an external program, i can say separate my various Qwidget into individual smaller program, the only thing is not sure how to share data in between process.

                  And that's the whole point. Sharing data between processes is horrific & slow compared to what you do inside a single process.

                  Unless you describe your needs/plan in detail, purely at a guess I would imagine separate processes is likely to be the wrong choice.

                  And P.S. If when you talk about "widget" you mean a UI element to be used in a single program, you can't somehow have bits of UI running in a separate process.

                  S 1 Reply Last reply 2 May 2018, 19:21
                  1
                  • J JonB
                    2 May 2018, 18:58

                    @s002wjh said in multi-process:

                    @koahnig
                    as i understand Qprocess start an external program, i can say separate my various Qwidget into individual smaller program, the only thing is not sure how to share data in between process.

                    And that's the whole point. Sharing data between processes is horrific & slow compared to what you do inside a single process.

                    Unless you describe your needs/plan in detail, purely at a guess I would imagine separate processes is likely to be the wrong choice.

                    And P.S. If when you talk about "widget" you mean a UI element to be used in a single program, you can't somehow have bits of UI running in a separate process.

                    S Offline
                    S Offline
                    s002wjh
                    wrote on 2 May 2018, 19:21 last edited by s002wjh 5 Feb 2018, 19:22
                    #9

                    @JonB
                    i see thanks what about qtconcurrent. basically i have 3 window/plotting that grab data from same place, do the same thing, but i like all 3 run concurrently.

                    also is qtconcurrent only run functions within the class ?

                    for example can i run test_pt and test_pt2 concurrently?

                    class test_c : public QWidget
                    {
                    Q_OBJECT
                    public:
                    void fuc1();
                    void fuc2();
                    signals:
                    void fuc_signal();
                    public slots:
                    void fuc_slot();
                    };

                    Main_w::Main_w(QWidget *parent)
                    : QWidget(parent)
                    {

                    //like to run test_pt and test_pt2 concurrently
                    test_c *test_pt,*test_pt2;
                    test_pt = new test_c;
                    test_pt->show();

                    test_pt2 = new test_c;
                    test_pt2->show();

                    }

                    J 1 Reply Last reply 2 May 2018, 19:46
                    0
                    • S s002wjh
                      2 May 2018, 19:21

                      @JonB
                      i see thanks what about qtconcurrent. basically i have 3 window/plotting that grab data from same place, do the same thing, but i like all 3 run concurrently.

                      also is qtconcurrent only run functions within the class ?

                      for example can i run test_pt and test_pt2 concurrently?

                      class test_c : public QWidget
                      {
                      Q_OBJECT
                      public:
                      void fuc1();
                      void fuc2();
                      signals:
                      void fuc_signal();
                      public slots:
                      void fuc_slot();
                      };

                      Main_w::Main_w(QWidget *parent)
                      : QWidget(parent)
                      {

                      //like to run test_pt and test_pt2 concurrently
                      test_c *test_pt,*test_pt2;
                      test_pt = new test_c;
                      test_pt->show();

                      test_pt2 = new test_c;
                      test_pt2->show();

                      }

                      J Online
                      J Online
                      JonB
                      wrote on 2 May 2018, 19:46 last edited by JonB 5 Feb 2018, 19:47
                      #10

                      @s002wjh
                      With my very limited knowledge of Qt, my understanding is that UI operations must all be actually performed in one thread, the main thread. That would imply that your actual "pixel plotting"s would not be parallel. However, if you are looking for efficiency, the usual way to speed up is to do the "grab data from same place" concurrently in their own threads. Would that approach help your situation?

                      So far as I know, QtConcurrent will run any function, not necessarily one defined in the class from which it is called.

                      However, if an expert comes here they will know much better than I :)

                      S 1 Reply Last reply 2 May 2018, 19:50
                      0
                      • J JonB
                        2 May 2018, 19:46

                        @s002wjh
                        With my very limited knowledge of Qt, my understanding is that UI operations must all be actually performed in one thread, the main thread. That would imply that your actual "pixel plotting"s would not be parallel. However, if you are looking for efficiency, the usual way to speed up is to do the "grab data from same place" concurrently in their own threads. Would that approach help your situation?

                        So far as I know, QtConcurrent will run any function, not necessarily one defined in the class from which it is called.

                        However, if an expert comes here they will know much better than I :)

                        S Offline
                        S Offline
                        s002wjh
                        wrote on 2 May 2018, 19:50 last edited by s002wjh 5 Feb 2018, 19:51
                        #11

                        @JonB

                        yes in qtconcurrent it says run functions, but i'm curious if it can run my two object(above) concurrently which include several functions.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 2 May 2018, 19:54 last edited by
                          #12

                          Hi,

                          Objects can't be "run".

                          What you can do is run a function that'll take one of your object in parameter like described here.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 1 Reply Last reply 2 May 2018, 20:29
                          2
                          • SGaistS SGaist
                            2 May 2018, 19:54

                            Hi,

                            Objects can't be "run".

                            What you can do is run a function that'll take one of your object in parameter like described here.

                            S Offline
                            S Offline
                            s002wjh
                            wrote on 2 May 2018, 20:29 last edited by
                            #13

                            @SGaist

                            anyway to run (below) without declear QtConcurrent::run(aFunction); for all the function within the object?

                            in the qtread i can just

                            testc= new test_c;
                            QThread sort;
                            testc->moveToThread(&sort);
                            sort.start();

                            anyway to tell QT all the functions in testc object should be run in different process/thread?

                            class test_c : public QWidget
                            {
                            Q_OBJECT
                            public:
                            void fuc1();
                            void fuc2();
                            signals:
                            void fuc_signal();
                            public slots:
                            void fuc_slot();
                            };

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 2 May 2018, 20:32 last edited by
                              #14

                              How are you calling these function in the first place ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                s002wjh
                                wrote on 2 May 2018, 20:52 last edited by s002wjh 5 Feb 2018, 20:59
                                #15

                                structure is kind like this. if i can run test_pt or pt2 in different thread or process or concurrently.

                                class test_c : public QWidget
                                {
                                Q_OBJECT

                                public:

                                test_c();
                                void fuc1();
                                void fuc2(); 
                                

                                signals:
                                void fuc_signal();

                                public slots:
                                void fuc_slot();
                                };

                                Main_w::Main_w(QWidget *parent)
                                : QWidget(parent)
                                {

                                test_c *test_pt,*test_pt2;
                                test_pt = new test_c();
                                test_pt->show();

                                test_pt2 = new test_c();
                                test_pt2->show();

                                connect(test_pt,signal(fuc_signal()), test_pt, slot(fuc_slot()));
                                connect(test_pt2,signal(fuc_signal()), test_pt2, slot(fuc_slot()));
                                emit signal for test_pt;
                                emit signal for test_pt2;

                                }

                                test_c::test_c{
                                //constructor do some init setup

                                //have some local signal/slot

                                }
                                test_c::fuc_slot(){
                                fuc1();
                                fuc2();
                                }

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 2 May 2018, 20:57 last edited by
                                  #16

                                  You can't emit signals from other classes, only from within said classes.

                                  You should rather use QMetaObject::invokeMethod.

                                  As my fellows already suggested, don't call methods that can modify your GUI content directly from another thread.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  S 1 Reply Last reply 2 May 2018, 21:43
                                  0
                                  • SGaistS SGaist
                                    2 May 2018, 20:57

                                    You can't emit signals from other classes, only from within said classes.

                                    You should rather use QMetaObject::invokeMethod.

                                    As my fellows already suggested, don't call methods that can modify your GUI content directly from another thread.

                                    S Offline
                                    S Offline
                                    s002wjh
                                    wrote on 2 May 2018, 21:43 last edited by
                                    #17

                                    @SGaist

                                    i probably make some mistake by hastelly make some example, i can't put actual code on here

                                    my main question is, is there anyway to use qtconcurrent or other qtclass so it can move entire object to different thread or process for concurrent operation? maybe something similar to movetothread?

                                    while qtconcurrent is useful but it seem only allow to put function in different thread. If i have 100 functions in my class, and i want to run all those in a separated processs or thread, i'm not sure what option have.

                                    jsulmJ 1 Reply Last reply 3 May 2018, 04:35
                                    0
                                    • S s002wjh
                                      2 May 2018, 21:43

                                      @SGaist

                                      i probably make some mistake by hastelly make some example, i can't put actual code on here

                                      my main question is, is there anyway to use qtconcurrent or other qtclass so it can move entire object to different thread or process for concurrent operation? maybe something similar to movetothread?

                                      while qtconcurrent is useful but it seem only allow to put function in different thread. If i have 100 functions in my class, and i want to run all those in a separated processs or thread, i'm not sure what option have.

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 3 May 2018, 04:35 last edited by
                                      #18

                                      @s002wjh It does not make sense to run 100 threads in parallel.
                                      Also, as already said here, you can't use GUI related classes in other threads than main thread!
                                      You need to understand the difference between a thread and a process. Using processes you would need to use IPC - inter process communication, which is neither easy nor fast. And moving part of your widgets to another process does not make sense.
                                      You should read this: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

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

                                      S 1 Reply Last reply 3 May 2018, 14:08
                                      2
                                      • jsulmJ jsulm
                                        3 May 2018, 04:35

                                        @s002wjh It does not make sense to run 100 threads in parallel.
                                        Also, as already said here, you can't use GUI related classes in other threads than main thread!
                                        You need to understand the difference between a thread and a process. Using processes you would need to use IPC - inter process communication, which is neither easy nor fast. And moving part of your widgets to another process does not make sense.
                                        You should read this: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

                                        S Offline
                                        S Offline
                                        s002wjh
                                        wrote on 3 May 2018, 14:08 last edited by s002wjh 5 Mar 2018, 14:09
                                        #19

                                        @jsulm said in multi-process:

                                        @s002wjh It does not make sense to run 100 threads in parallel.
                                        Also, as already said here, you can't use GUI related classes in other threads than main thread!
                                        You need to understand the difference between a thread and a process. Using processes you would need to use IPC - inter process communication, which is neither easy nor fast. And moving part of your widgets to another process does not make sense.
                                        You should read this: https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

                                        i not saying each functions is a thread but run exact same 100 function in main thread, then run exact 100 function in another thread that has different input data.

                                        thx thats what i was looking for, i know i can't run GUI class in other thread but still hope there are other QT class to do that. Now i know the only way to do that is via processes, and its sounds painful.

                                        as for qtconcurrent. how is the data(struct) transfer between functions within different thread? is it

                                        struct mystruc
                                        {
                                           char name[50];
                                        float test[100];  
                                           int pin;
                                        };

                                        QFuture<void> future = QtConcurrent::run(myfunc, mystruc);

                                        mystruc test_s=future.result(); ?

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 3 May 2018, 14:34 last edited by
                                          #20

                                          See the QtConcurrent run chapter of Qt's documentation. It explains how to pass parameters to function call.

                                          As was already explained, multiple processes won't help in your case because you are going to have to setup IPC to exchange data between everybody involved.

                                          If you'd explain what exactly your hundred functions are supposed to do, then it would be possible to help you.

                                          Note that a class that has to run that many functions to do its job doesn't sound good especially when threading is involved.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          1

                                          1/20

                                          2 May 2018, 14:06

                                          • Login

                                          • Login or register to search.
                                          1 out of 20
                                          • First post
                                            1/20
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved