Results 1 to 10 of 10

Thread: multithreading

  1. #1
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default multithreading

    how to run two threads parallel...give simple example code

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: multithreading

    Qt Code:
    1. QThread *thread1 = new QThread;
    2. QThread *thread2 = new QThread;
    3. thread1->start();
    4. thread2->start();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    May 2017
    Posts
    5
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Multithreading using qt

    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?

  4. #4
    Join Date
    May 2017
    Posts
    5
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: multithreading

    but how can you perform two separate run function for this threads?

  5. #5
    Join Date
    May 2017
    Posts
    5
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Multithreading using qt

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Multithreading using qt

    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

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multithreading using qt

    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.

  8. #8
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Multithreading using qt

    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

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Multithreading using qt

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

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Multithreading using qt

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

Similar Threads

  1. Multithreading & GUI
    By qthread in forum Qt Programming
    Replies: 22
    Last Post: 24th August 2014, 10:37
  2. Multithreading
    By havij000 in forum Newbie
    Replies: 22
    Last Post: 21st August 2013, 13:35
  3. When to use Multithreading?
    By "BumbleBee" in forum General Programming
    Replies: 5
    Last Post: 30th April 2011, 18:21
  4. regarding multithreading
    By mohanakrishnan in forum Qt Programming
    Replies: 19
    Last Post: 9th December 2009, 08:21
  5. multithreading
    By mickey in forum General Programming
    Replies: 2
    Last Post: 5th June 2008, 22:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.