Results 1 to 3 of 3

Thread: Using QThread

  1. #1
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    2

    Question Using QThread

    Hi there,

    I need some help on including threads on some widget I have done some weeks ago.

    I have a module that build reports over some database data. When I first build it, I just wanted to get one report at a time and so i didn't use QThread.

    Now, I want to run more than one report at a time. My problem is that I can't figure out how to use threads on my already built module.

    I have a module called ReportViewWidget that runs one report at a time and updates its GUI with a result preview. Once the report execution time can sometimes be of 10 or more minutes, I want to be able to run another report while the first still running.

    Can I include ReportViewWidget class in a myThread class and include myThread class into ReportViewWidget at the same time?

    Can anyone help me with some idea?


    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QThread

    First you must understand that widgets cannot be used/modified directly in worker threads. Only the GUI thread can do it.

    One way to do it is to start a thread that creates a report in the moment you need one. If you need more reports then start more threads. For example, if you need 6 reports, then you could start 3 threads; 2 reports for each thread.
    If a thread finishes earlier, then it could take the task off some other thread that's still at the first report. This assumes that you have the tasks in a static data structure accessible by all threads. They should all query this data structure when they have nothing to do to see if something is available. If it is not, then you should delete them.

    However, I don't know how your code looks like, but I think you mixed the report generation logic with the view logic. You should separate them.

    The view module should run in the GUI thread, while the other by the worker threads.

    I guess this is one solution.

    Regards

  3. #3
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    2

    Default Re: Using QThread

    Yes, you are right marcel. When I first start to write this module I was really noob to QT. My programming method wasn't helpfull either. I mixed a little the presentation with the logic and computation one. I have to solve that first in order to correctly use threads on the report generation.

    I Like your idea about keeping track of unused/finished threads. But I think that at least for now, the application will be used to allow only 3 (maximum 4) to be running at the same time.


    Thanks marcel. If you or somebody else have anything else to say regarding this thread, please do. It's very nice to read from experienced people like some of you guys.

Similar Threads

  1. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  2. Qthread Issue?
    By vishal.chauhan in forum Newbie
    Replies: 3
    Last Post: 29th March 2007, 08:50
  3. QGraphicsScene and QThread
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2007, 09:32
  4. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

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.