Results 1 to 4 of 4

Thread: Letting a QThread take control over single items in a QWidget

  1. #1
    Join Date
    Nov 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Letting a QThread take control over single items in a QWidget

    Hello,

    at the moment i try to program a simple multithreaded internet search application. In the beginning, there is one QWidget with an input field and a push button. upon pressing the pushbutton, a new qwidget pops up containing two QWebViews, each of those searching for the same query, one through google and the other one through wikipedia.

    The problem is the multithreading. I want to design it, so that each QWebView runs in its own thread using QThread, thus performing the rendering in different threads.
    Now, how can i let a class deriving from QThread create a QWebView which will be displayed in another class's QWidget?

    thank you for your time! if you need further information i am more than happy to share it with you!

    yours sincerely
    replax

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

    Default Re: Letting a QThread take control over single items in a QWidget

    I want to design it, so that each QWebView runs in its own thread using QThread, thus performing the rendering in different threads.
    Doesn't work with Qt.
    All GUI rendering must run in the main GUI thread.
    You probably don't mean that however.
    I guess you want the queries to be done in their own thread, not the rendering of the results.
    But even that makes little sens to me.
    Its not your application which is doing the search.
    You application just waits for the results to the queries it sent, the searching is done in parallel by google and what ever other sites you sent your queries to, you only sit there and wait for the results.
    So what do you need threads for?
    ==========================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.

  3. #3
    Join Date
    Nov 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Letting a QThread take control over single items in a QWidget

    thanks for your quick reply!

    yes, you are correct, my application just passes the queries and then recieves and displays the results from google etc.
    i was trying to seperate the processing and rendering of the two qwebviews into threads to achieve a better performance when rendering more than one qwebview at the same time. it might not make sense, since the performance gain would be equal to zero, but my purpose behind all this was to learn more about qthreads and get familar with them before using threading in a bigger project.
    so i guess it would not be possible without implenting threading in qwebview itself, which would be far too complicated for me.

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

    Default Re: Letting a QThread take control over single items in a QWidget

    Well, in general, you should use threads only for tasks that take long time, and you want to keep your gui resposive, and / or, when a sequential processing of several computation would take long, then you can process them in parallel.
    But as you can see, in all the cases, you are not doing GUI in the threads, only data crunching.
    So, using Qt with threads is really quite simple:
    You cerate the object that encapsulates your work.
    You move it to a thread.
    You start the thread.
    Somewhere else you wait for the thread finished signal.
    Thats it.

    Of course, this is a simple case, but it should cover most normal cases where threads are needed.
    ==========================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. change QWidget from QThread classes
    By radeberger in forum Qt Programming
    Replies: 12
    Last Post: 30th May 2010, 19:45
  2. Replies: 1
    Last Post: 15th May 2010, 18:22
  3. Letting Widgets from different files get to know each other
    By FlashMuller in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2010, 23:20
  4. Control MainWindow from QThread
    By lixo1 in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2009, 10:33
  5. insertion of multiple items in a single row
    By grimbaum in forum Qt Programming
    Replies: 4
    Last Post: 17th November 2006, 05:36

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.