how to run two threads parallel...give simple example code
how to run two threads parallel...give simple example code
Qt Code:
thread1->start(); thread2->start();To copy to clipboard, switch view to plain text mode
Cheers,
_
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 separate threads?
but how can you perform two separate run function for this threads?
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 separate threads?
Hi,
Create a QThread inherited class.
Create a method in this class to pass a pointer to the queue you want to parse.
Redefine "run" method in this class and code your parsing code there.
Now, for each queue you have to create one object of this class and call "start" on each object.
Then, for each queue you have to call "wait" on the object to wait it for finish.
Finally you can get the parsed data on you object.
Òscar Llarch i Galán
Multi threading is a complex issue.
You can't learn it by asking "how do I multithread" in a forum.
As always start with the documentation: http://doc.qt.io/qt-5/threads-technologies.html
THEN, come back and ask specific questions, clarifications etc.
EDIT:
and please stop "multi threading" on the forum - stop opening new threads with the same question.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
high_flyer,
Thank you for suggesting "The Foundations of Qt Development (ISBN: 1-59059-831-8)"
I searched on Amazon.com and found it is a 2007 book.
Is the material in this book still applicable (i.e. its example code compiles & runs without errors ?) using Qt 5 please?
Thanks
Yes, mostly. It is based on Qt 4, but Qt 5 mostly adds features to Qt 4 and changes only a small number of the older features.Is the material in this book still applicable
Mostly no. From Qt 4 to Qt 5 the organization of the Qt distribution completely changed, including the locations of Qt header files and the names of Qt libraries. In addition, some of the arguments to basic functions changed.(i.e. its example code compiles & runs without errors ?) using Qt 5 please?
The best way to proceed is to load the project into Qt Creator, configure it to use your current Qt distribution, then try to build it. Look at what the compiler or linker tell you is wrong, fix them, and build again. The process will be the same for almost every example and once you get it for the first one, the rest will follow the same pattern.
There are newer books that are Qt 5 based, such as the one by Wysota and Haas (which you will also find on Amazon).
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Just in case it was not clear, its part of my signature.Thank you for suggesting "The Foundations of Qt Development (ISBN: 1-59059-831-8)"
At the time when I put it in my signature, this book was the newest (btw, written by e8johan).
I probably should update my signature :-)
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks