Results 1 to 2 of 2

Thread: Thread support

  1. #1
    Join Date
    Dec 2006
    Posts
    17
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Thread support

    Hi guys,

    Iam using Qt4.2's Theads in my application.

    I have 2 threads:
    1. Gui thread ( QGraphicsView)
    2. Worker thread.

    In my single threaded application. I have a method called CreateFabrics, which reads information in a data structure each time to create GraphicsItem ( Lot of graphicsItem are created). My application takes a lot of time in this case.

    In my Multithreaded application -

    Worker thread reads the populated datastructures and creates GraphicItems- ( inherited from QGraphicsItem) but i dont display it( As the doc says: Only main Thread can write to display).

    My questions are -
    1. Is it ok ,if i create items in other thread.
    2. Will there be any performance improvement .If i run this on a multiprocessor machine.
    3. How to compare the performance of single thraeded application and multithreaded
    app.

    Thanks

  2. #2
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Thread support

    Quote Originally Posted by kiranraj View Post
    My questions are -
    1. Is it ok ,if i create items in other thread.
    2. Will there be any performance improvement .If i run this on a multiprocessor machine.
    3. How to compare the performance of single thraeded application and multithreaded
    app.
    1. Sure, as long as you use queued connections and register the datatype (if necessary, not sure about which ones are registered by default. This needs to be done so Qt can send the datatype over a queued connection) with:
    Qt Code:
    1. qRegisterMetaType<Type>("typeName");
    To copy to clipboard, switch view to plain text mode 

    2. Yes. Right now your single processor is just switching really fast between the two threads of execution. [edit] Disclaimer: this may or may not be true. Depending on the multiprocessing machine used, your threads (part of the same process) may still run on a single processor. Some multiprocessor machines allow you to schedule how the tasks should be divided amongst the processors. It should still be faster though since you've got several processors sharing the work load (provided they're not super slow compared to your single processor). [/edit]

    3. That depends on how you define 'performance'. If you mean execution time, you can use a QTimer to measure the time it takes for a task to be completed. I'm sure you'll find the single threaded application to be faster. If you have a very computationally intensive task to perform though, it will/may lock up your GUI.
    Last edited by TheRonin; 9th March 2007 at 08:38.

Similar Threads

  1. Compile QT4.2.2 with MySQL on Mac OS
    By asd in forum Installation and Deployment
    Replies: 7
    Last Post: 12th February 2007, 14:50
  2. how to provide thread support to qt
    By amit_pansuria in forum Installation and Deployment
    Replies: 3
    Last Post: 24th November 2006, 04:48
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  4. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  5. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35

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.