How to run two functions of the same class in different threads
Hi I have a class named search and this class has two member functions. The consumer and the producer. This is the way I have activated these functions as two threads in qt.
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search() ;
mySearch->moveToThread(thread1);
mySearch->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),mySearch, SLOT(producer()));
connect(thread2, SIGNAL(started()),mySearch, SLOT(consumer()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
But, it seems that only one is activated. How should I activate both. Please let me know with an example.
Thanks.
qt class qthread
add a comment |
Hi I have a class named search and this class has two member functions. The consumer and the producer. This is the way I have activated these functions as two threads in qt.
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search() ;
mySearch->moveToThread(thread1);
mySearch->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),mySearch, SLOT(producer()));
connect(thread2, SIGNAL(started()),mySearch, SLOT(consumer()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
But, it seems that only one is activated. How should I activate both. Please let me know with an example.
Thanks.
qt class qthread
3
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51
add a comment |
Hi I have a class named search and this class has two member functions. The consumer and the producer. This is the way I have activated these functions as two threads in qt.
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search() ;
mySearch->moveToThread(thread1);
mySearch->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),mySearch, SLOT(producer()));
connect(thread2, SIGNAL(started()),mySearch, SLOT(consumer()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
But, it seems that only one is activated. How should I activate both. Please let me know with an example.
Thanks.
qt class qthread
Hi I have a class named search and this class has two member functions. The consumer and the producer. This is the way I have activated these functions as two threads in qt.
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search() ;
mySearch->moveToThread(thread1);
mySearch->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),mySearch, SLOT(producer()));
connect(thread2, SIGNAL(started()),mySearch, SLOT(consumer()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
But, it seems that only one is activated. How should I activate both. Please let me know with an example.
Thanks.
qt class qthread
qt class qthread
asked Nov 21 '18 at 14:09
zahrazahra
3218
3218
3
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51
add a comment |
3
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51
3
3
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51
add a comment |
1 Answer
1
active
oldest
votes
This is a simple example to run the two methods of the same object in two different threads. Assuming your Search
class looks like this:
class Search : public QObject
{
Q_OBJECT
public:
void producer();
void consumer();
signals:
void workRequested();
void finishedscan();
};
You would create a second class like this:
class Worker : public QObject
{
Q_OBJECT
public:
Worker(std::function<void()> task) :
QObject{},
_task{std::move(task)}
{}
public slots:
void work() {
_task();
}
private:
std::function<void()> _task;
};
And now you can implement the start:
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search();
auto worker1 = new Worker(std::bind(&Search::producer, mySearch));
auto worker2 = new Worker(std::bind(&Search::consumer, mySearch));
worker1->moveToThread(thread1);
worker2->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),worker1, SLOT(work()));
connect(thread2, SIGNAL(started()),worker2, SLOT(work()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
Important: While this solution solves how to start the two tasks on different threads, stopping won't work yet as QThread::quit
only works if the thread returns to the eventloop! If your producer/consumer methods do not return to the eventloop and use it to perform tasks, write so in the comments and I will update the answer to handle that case as well.
EDIT: Since stopping i the above solution only works, if producer/consumer return to the eventloop - which is not the case according to OP, you have to manually notify the worker that it should stop working to gracefully quit the thread.
For the first solution, your worker has to periodically check, if it should stop working. For example:
MySearch::producer() {
while(!QThread::currentThread()->isInterruptionRequested() {
//do some work
}
}
And secondly, you have to adjust how you quit the thread:
connect(mySearch, &MySearch::finishedscan, thread1, [thread1](){
thread1->requestInterruption();
thread1->quit();
}, Qt::DirectConnection);
Note: Regardless of how you quit your threads, you should always wait for them in the main thread to finish their work before exiting:
thread1->wait();
Finally, you mentioned in the comments that you use CTRL+C
to quit the application - make shure to register a signal handler to catch SIGINT
and stop you application gracefully, as the default SIGINT
will just terminate it, without proper cleanup
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either useterminate
or use logic inside the worker to handle the quit. I will update the answer
– Felix
Nov 28 '18 at 9:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413916%2fhow-to-run-two-functions-of-the-same-class-in-different-threads%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a simple example to run the two methods of the same object in two different threads. Assuming your Search
class looks like this:
class Search : public QObject
{
Q_OBJECT
public:
void producer();
void consumer();
signals:
void workRequested();
void finishedscan();
};
You would create a second class like this:
class Worker : public QObject
{
Q_OBJECT
public:
Worker(std::function<void()> task) :
QObject{},
_task{std::move(task)}
{}
public slots:
void work() {
_task();
}
private:
std::function<void()> _task;
};
And now you can implement the start:
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search();
auto worker1 = new Worker(std::bind(&Search::producer, mySearch));
auto worker2 = new Worker(std::bind(&Search::consumer, mySearch));
worker1->moveToThread(thread1);
worker2->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),worker1, SLOT(work()));
connect(thread2, SIGNAL(started()),worker2, SLOT(work()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
Important: While this solution solves how to start the two tasks on different threads, stopping won't work yet as QThread::quit
only works if the thread returns to the eventloop! If your producer/consumer methods do not return to the eventloop and use it to perform tasks, write so in the comments and I will update the answer to handle that case as well.
EDIT: Since stopping i the above solution only works, if producer/consumer return to the eventloop - which is not the case according to OP, you have to manually notify the worker that it should stop working to gracefully quit the thread.
For the first solution, your worker has to periodically check, if it should stop working. For example:
MySearch::producer() {
while(!QThread::currentThread()->isInterruptionRequested() {
//do some work
}
}
And secondly, you have to adjust how you quit the thread:
connect(mySearch, &MySearch::finishedscan, thread1, [thread1](){
thread1->requestInterruption();
thread1->quit();
}, Qt::DirectConnection);
Note: Regardless of how you quit your threads, you should always wait for them in the main thread to finish their work before exiting:
thread1->wait();
Finally, you mentioned in the comments that you use CTRL+C
to quit the application - make shure to register a signal handler to catch SIGINT
and stop you application gracefully, as the default SIGINT
will just terminate it, without proper cleanup
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either useterminate
or use logic inside the worker to handle the quit. I will update the answer
– Felix
Nov 28 '18 at 9:47
add a comment |
This is a simple example to run the two methods of the same object in two different threads. Assuming your Search
class looks like this:
class Search : public QObject
{
Q_OBJECT
public:
void producer();
void consumer();
signals:
void workRequested();
void finishedscan();
};
You would create a second class like this:
class Worker : public QObject
{
Q_OBJECT
public:
Worker(std::function<void()> task) :
QObject{},
_task{std::move(task)}
{}
public slots:
void work() {
_task();
}
private:
std::function<void()> _task;
};
And now you can implement the start:
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search();
auto worker1 = new Worker(std::bind(&Search::producer, mySearch));
auto worker2 = new Worker(std::bind(&Search::consumer, mySearch));
worker1->moveToThread(thread1);
worker2->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),worker1, SLOT(work()));
connect(thread2, SIGNAL(started()),worker2, SLOT(work()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
Important: While this solution solves how to start the two tasks on different threads, stopping won't work yet as QThread::quit
only works if the thread returns to the eventloop! If your producer/consumer methods do not return to the eventloop and use it to perform tasks, write so in the comments and I will update the answer to handle that case as well.
EDIT: Since stopping i the above solution only works, if producer/consumer return to the eventloop - which is not the case according to OP, you have to manually notify the worker that it should stop working to gracefully quit the thread.
For the first solution, your worker has to periodically check, if it should stop working. For example:
MySearch::producer() {
while(!QThread::currentThread()->isInterruptionRequested() {
//do some work
}
}
And secondly, you have to adjust how you quit the thread:
connect(mySearch, &MySearch::finishedscan, thread1, [thread1](){
thread1->requestInterruption();
thread1->quit();
}, Qt::DirectConnection);
Note: Regardless of how you quit your threads, you should always wait for them in the main thread to finish their work before exiting:
thread1->wait();
Finally, you mentioned in the comments that you use CTRL+C
to quit the application - make shure to register a signal handler to catch SIGINT
and stop you application gracefully, as the default SIGINT
will just terminate it, without proper cleanup
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either useterminate
or use logic inside the worker to handle the quit. I will update the answer
– Felix
Nov 28 '18 at 9:47
add a comment |
This is a simple example to run the two methods of the same object in two different threads. Assuming your Search
class looks like this:
class Search : public QObject
{
Q_OBJECT
public:
void producer();
void consumer();
signals:
void workRequested();
void finishedscan();
};
You would create a second class like this:
class Worker : public QObject
{
Q_OBJECT
public:
Worker(std::function<void()> task) :
QObject{},
_task{std::move(task)}
{}
public slots:
void work() {
_task();
}
private:
std::function<void()> _task;
};
And now you can implement the start:
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search();
auto worker1 = new Worker(std::bind(&Search::producer, mySearch));
auto worker2 = new Worker(std::bind(&Search::consumer, mySearch));
worker1->moveToThread(thread1);
worker2->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),worker1, SLOT(work()));
connect(thread2, SIGNAL(started()),worker2, SLOT(work()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
Important: While this solution solves how to start the two tasks on different threads, stopping won't work yet as QThread::quit
only works if the thread returns to the eventloop! If your producer/consumer methods do not return to the eventloop and use it to perform tasks, write so in the comments and I will update the answer to handle that case as well.
EDIT: Since stopping i the above solution only works, if producer/consumer return to the eventloop - which is not the case according to OP, you have to manually notify the worker that it should stop working to gracefully quit the thread.
For the first solution, your worker has to periodically check, if it should stop working. For example:
MySearch::producer() {
while(!QThread::currentThread()->isInterruptionRequested() {
//do some work
}
}
And secondly, you have to adjust how you quit the thread:
connect(mySearch, &MySearch::finishedscan, thread1, [thread1](){
thread1->requestInterruption();
thread1->quit();
}, Qt::DirectConnection);
Note: Regardless of how you quit your threads, you should always wait for them in the main thread to finish their work before exiting:
thread1->wait();
Finally, you mentioned in the comments that you use CTRL+C
to quit the application - make shure to register a signal handler to catch SIGINT
and stop you application gracefully, as the default SIGINT
will just terminate it, without proper cleanup
This is a simple example to run the two methods of the same object in two different threads. Assuming your Search
class looks like this:
class Search : public QObject
{
Q_OBJECT
public:
void producer();
void consumer();
signals:
void workRequested();
void finishedscan();
};
You would create a second class like this:
class Worker : public QObject
{
Q_OBJECT
public:
Worker(std::function<void()> task) :
QObject{},
_task{std::move(task)}
{}
public slots:
void work() {
_task();
}
private:
std::function<void()> _task;
};
And now you can implement the start:
thread1 = new QThread();
thread2 = new QThread();
mySearch = new Search();
auto worker1 = new Worker(std::bind(&Search::producer, mySearch));
auto worker2 = new Worker(std::bind(&Search::consumer, mySearch));
worker1->moveToThread(thread1);
worker2->moveToThread(thread2);
connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
connect(mySearch, SIGNAL(workRequested()), thread2, SLOT(start()));
connect(thread1, SIGNAL(started()),worker1, SLOT(work()));
connect(thread2, SIGNAL(started()),worker2, SLOT(work()));
connect(mySearch, SIGNAL(finishedscan()), thread1, SLOT(quit()), Qt::DirectConnection);
connect(mySearch, SIGNAL(finishedscan()), thread2, SLOT(quit()), Qt::DirectConnection);
Important: While this solution solves how to start the two tasks on different threads, stopping won't work yet as QThread::quit
only works if the thread returns to the eventloop! If your producer/consumer methods do not return to the eventloop and use it to perform tasks, write so in the comments and I will update the answer to handle that case as well.
EDIT: Since stopping i the above solution only works, if producer/consumer return to the eventloop - which is not the case according to OP, you have to manually notify the worker that it should stop working to gracefully quit the thread.
For the first solution, your worker has to periodically check, if it should stop working. For example:
MySearch::producer() {
while(!QThread::currentThread()->isInterruptionRequested() {
//do some work
}
}
And secondly, you have to adjust how you quit the thread:
connect(mySearch, &MySearch::finishedscan, thread1, [thread1](){
thread1->requestInterruption();
thread1->quit();
}, Qt::DirectConnection);
Note: Regardless of how you quit your threads, you should always wait for them in the main thread to finish their work before exiting:
thread1->wait();
Finally, you mentioned in the comments that you use CTRL+C
to quit the application - make shure to register a signal handler to catch SIGINT
and stop you application gracefully, as the default SIGINT
will just terminate it, without proper cleanup
edited Nov 28 '18 at 9:58
answered Nov 26 '18 at 10:58
FelixFelix
4,78011940
4,78011940
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either useterminate
or use logic inside the worker to handle the quit. I will update the answer
– Felix
Nov 28 '18 at 9:47
add a comment |
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either useterminate
or use logic inside the worker to handle the quit. I will update the answer
– Felix
Nov 28 '18 at 9:47
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
Thanks for your response. I don't exactly understand what you mean by event loop. Both the producer and consumer thread keep on working until I use ctrl+c. The producer fills the buffer and the consumer reads the buffer and shows the values in a Qtable @Felix
– zahra
Nov 28 '18 at 9:08
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either use
terminate
or use logic inside the worker to handle the quit. I will update the answer– Felix
Nov 28 '18 at 9:47
In that case, using quit will not work (you should really read on QThread to understand how it works). You can either use
terminate
or use logic inside the worker to handle the quit. I will update the answer– Felix
Nov 28 '18 at 9:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413916%2fhow-to-run-two-functions-of-the-same-class-in-different-threads%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
A QObject can only "live" in a single thread. Thats by definition. You could create a wrapper around "Search" and let each wrapper live in a seperate thread
– Felix
Nov 21 '18 at 14:32
Thanks. I have a common circular buffer between these two threads. Will the consumer thread follow the changes of the buffer made by the producer if I define separate wrappers for each thread? If I write the two functions in two different classes then were should I define the common circular buffer? In the producer class or the consumer class? @Felix
– zahra
Nov 26 '18 at 5:51