multi-process
-
wrote on 2 May 2018, 14:06 last edited by
is Qprocess class can be use for multi-process? if not what QT class is used to run multiple process.
-
is Qprocess class can be use for multi-process? if not what QT class is used to run multiple process.
wrote on 2 May 2018, 14:10 last edited byQProcess can be used to start several external processes in parallel.
For multi-threading check out threads-technologies.
-
wrote on 2 May 2018, 15:00 last edited by s002wjh 5 Feb 2018, 15:04
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
-
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
wrote on 2 May 2018, 15:40 last edited by koahnig 5 Feb 2018, 19:03It 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
-
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
wrote on 2 May 2018, 18:15 last edited by@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. -
@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.wrote on 2 May 2018, 18:50 last edited byYou 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. -
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.wrote on 2 May 2018, 18:53 last edited by s002wjh 5 Feb 2018, 18:56@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
-
@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
wrote on 2 May 2018, 18:58 last edited by JonB 5 Feb 2018, 19:14@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.
-
@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.
wrote on 2 May 2018, 19:21 last edited by s002wjh 5 Feb 2018, 19:22@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();}
-
@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();}
wrote on 2 May 2018, 19:46 last edited by JonB 5 Feb 2018, 19:47@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 :)
-
@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 :)
-
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.
-
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.
wrote on 2 May 2018, 20:29 last edited byanyway 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();
}; -
How are you calling these function in the first place ?
-
wrote on 2 May 2018, 20:52 last edited by s002wjh 5 Feb 2018, 20:59
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_OBJECTpublic:
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();
} -
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.
-
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.
wrote on 2 May 2018, 21:43 last edited byi 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.
-
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.
@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/ -
@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/wrote on 3 May 2018, 14:08 last edited by s002wjh 5 Mar 2018, 14:09@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(); ?
-
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.
1/20