Multithreading using qt
-
Hi @jish,
maybe you have a look at the QThread class, which manages threads!If you move your parser to the a thread and start it, the parser method should run in another thread.
Parser *myParser = new Parser(); myParser->moveToThread(&workerThread); ... connect(this, &MyClass::newQuery, myParser, &Parser::handleQuery); ... workerThread.start();
-
i want to use multithreading in my qt program.
My program is to continuously receive data from two message queues. After receiving data i have to parse it. so for each queue i have a parsing method. how can i run this as two seperate threads?@jish
there are different possibilities to use threading in Qt.
You should read Thread Basics and Multithreading Technologies in QtIf you already have the parsing logic, moving to threads shouldn't be a big deal anymore.
-
Wow, either the 3 of us posted simultaneously or I had some network lag - when I responded there were no other posts here :) Sorry for the noise
-
Hi @jish,
maybe you have a look at the QThread class, which manages threads!If you move your parser to the a thread and start it, the parser method should run in another thread.
Parser *myParser = new Parser(); myParser->moveToThread(&workerThread); ... connect(this, &MyClass::newQuery, myParser, &Parser::handleQuery); ... workerThread.start();
@beecksche Thank you. But for each start there should be a run function .right?
-
Use QThread, peferrably with worker objects - to save yourself from the trouble with locking and mutexes.