Results 1 to 13 of 13

Thread: Qt threads

  1. #1
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Qt threads

    Hi to all!
    I try to make my first multithreaded program. I use a linux system, but I don't think that has to do with anything. It happens that I don't have a past experience with threads. By now I didn't had to use but the main thread.

    Can you pls direct me to the right direction. Maybe a tutorial or some guidelines.

    Thank you for your time

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt threads

    A good point to start is always the documentation of Qt: Thread Support in Qt. And then ervery book for Qt handles threads.

  3. The following user says thank you to Lykurg for this useful post:

    ^Nisok^ (17th April 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    ok. So as far as I understand I have to subclass my class from QThread. But what if I want to subclass it from another custom class.

  5. #4
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    In order to be more specific...
    I read the data from a list file, then I process the data to produce an image. But I want to have a periodical check or new data. My first thought was to create a new thread which will be responsible of doing this check and then provide the new data to the process class.

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt threads

    Quote Originally Posted by ^Nisok^ View Post
    ok. So as far as I understand I have to subclass my class from QThread.
    That's right,
    But what if I want to subclass it from another custom class.
    If the custom class is a subclass of QThread then that's also fine. Or you can subclass from QThread and the other class...

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt threads

    Quote Originally Posted by ^Nisok^ View Post
    But I want to have a periodical check or new data.
    If your check for new data is quick (I guess so) just use a timer inside your main app. If data chanced use/fire a worker thread .

    My first thought was to create a new thread which will be responsible of doing this check and then provide the new data to the process class.
    You also can use signal and slots across the thread border

  8. #7
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    If I create a l class from a parent which runs on a separate thread then this class will also run on this thread?

  9. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt threads

    all objects which have been created in QThread::run will be in this thread.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #9
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    Ok, thanks and one final question on this tread. On the worker thread I created I have a matrix which I want to transfer to a class on the main thread, is there something I have to take care of, I heard that in order to communicate a thread with the main thread I have to setup a transaction, do you know a guide or something?

  11. #10
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    anyone?
    How to transfer data from a worker thread to the main thread?

  12. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt threads

    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #12
    Join Date
    Apr 2009
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt threads

    But this way will I lock the main thread during the data transfer??

  14. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt threads

    you need lock that thread which modify data and then you can send that data to another thread using signals or events.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  3. No context switch between Threads and parent ?
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 29th October 2008, 22:49
  4. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35

Tags for this Thread

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.