Results 1 to 8 of 8

Thread: Adding new Widgets in a seperate thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Adding new Widgets in a seperate thread

    Also consider the option of doing it all in a single thread. You don't need a separate thread just to receive data over network.

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding new Widgets in a seperate thread

    And how can I accomplish that? The data transfer is triggered by a button. So first thing that happens is that a signal (clicked()) is sent into a slot. Coming from Java Swing I was raised to return an event handler as quickly as possible, otherwise I will keep the gui thread busy and the gui itself will freeze. So this is why I decided to start a thread from there and to return the slot as quickly as possible. So unless Qt itself takes care of splitting out a thread to handle the slot, so that the gui is not blocked by my sluggish program, I don't see how I can solve it without a thread.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Adding new Widgets in a seperate thread

    Longer explanation is here:
    http://doc.trolltech.com/qq/qq27-responsive-guis.html

    In short, network transfer is asynchronous - you schedule some request and then return from the function and Qt will notify you using a signal that the data is ready. You can then process it (read it to a buffer or process immediately) and return from the function. When more data arrives, you will be notified again. In the meantime the application can do other things (like refresh the user interface or make coffee).

  4. The following user says thank you to wysota for this useful post:

    Cruz (16th January 2009)

  5. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding new Widgets in a seperate thread

    I see where you are coming from. Well, actually it's not really a network connection, it's a more complicated custom USB communication with a robot. I simplified that detail in my question. It means that I can't take advantage of the solid network com solutions that Qt offers. And with that being gone, I personally think that the worker thread is the most elegant solution from all the alternatives proposed on that page.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Adding new Widgets in a seperate thread

    Quote Originally Posted by Cruz View Post
    I see where you are coming from. Well, actually it's not really a network connection, it's a more complicated custom USB communication with a robot.
    That doesn't change anything. It's a remote data source, that's all that counts.

    It means that I can't take advantage of the solid network com solutions that Qt offers.
    Sure you can. You can read from USB in an asynchronous way, you can even use QExtSerialPort probably and there are always timers. Threads are really not required here.

    And with that being gone, I personally think that the worker thread is the most elegant solution from all the alternatives proposed on that page.
    Well... Java itself is said to be elegant and that probably ends its advantages over other languages. Doing everything in threads is a nice separation of code but it is often crude when it comes to communication with other components and it adds some overhead to the application. Using signals and slots and event-driven flow gives you the same separation without the down sides. Sure, it might look hard at first but once you grasp it, it becomes very natural.

Similar Threads

  1. Starting QT GUI in a seperate Thread
    By bbui210 in forum Qt Programming
    Replies: 8
    Last Post: 27th June 2018, 16:17
  2. Replies: 4
    Last Post: 2nd December 2008, 04:19
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Replies: 10
    Last Post: 20th March 2007, 22:19
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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
  •  
Qt is a trademark of The Qt Company.