PDA

View Full Version : multithreading



gayathrireddy
22nd November 2016, 10:18
how to run two threads parallel...give simple example code

anda_skoa
22nd November 2016, 12:49
QThread *thread1 = new QThread;
QThread *thread2 = new QThread;
thread1->start();
thread2->start();


Cheers,
_

jish
4th July 2017, 06:15
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?

jish
4th July 2017, 06:17
but how can you perform two separate run function for this threads?

jish
4th July 2017, 06:19
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?

^NyAw^
4th July 2017, 14:44
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.

high_flyer
4th July 2017, 15:14
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.

Mike_m
8th July 2017, 01:54
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

d_stranz
8th July 2017, 17:05
Is the material in this book still applicable

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.


(i.e. its example code compiles & runs without errors ?) using Qt 5 please?

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.

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).

high_flyer
10th July 2017, 09:19
Thank you for suggesting "The Foundations of Qt Development (ISBN: 1-59059-831-8)"
Just in case it was not clear, its part of my signature.
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 :-)