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

multi-process

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 4.9k Views 2 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.
  • K koahnig

    @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 last edited by s002wjh
    #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

    JonBJ 1 Reply Last reply
    0
    • S s002wjh

      @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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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
      1
      • JonBJ JonB

        @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 last edited by s002wjh
        #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();

        }

        JonBJ 1 Reply Last reply
        0
        • S s002wjh

          @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();

          }

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #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
          0
          • JonBJ JonB

            @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 last edited by s002wjh
            #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 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
              • SGaistS SGaist

                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 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 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 last edited by s002wjh
                    #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 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
                      0
                      • SGaistS SGaist

                        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 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
                        0
                        • S s002wjh

                          @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 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
                          2
                          • jsulmJ jsulm

                            @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 last edited by s002wjh
                            #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 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

                              • Login

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