Results 1 to 7 of 7

Thread: QThread blocks gui

  1. #1
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QThread blocks gui

    For learning Qt programming I'm working on a little gpl project: http://pertubis.berlios.de

    you can obtain the source code via svn:

    Qt Code:
    1. svn checkout svn://svn.berlios.de/pertubis/trunk/pertubis
    To copy to clipboard, switch view to plain text mode 
    or browse the code:


    It's a bit tricky compiling since you need the (unstable) trunk version of paludis installed to link with, and an up-to-date gentoo system.

    Now I have encountered a problem with a QThread derived class "src/ItemInstallTask.{cc,hh}", which handles package compilation and installation. The QThread::run() method only calls a predefined function from paludis api, which is doing the dirty work. While the thread is running, the Gui is completely blocked. I don't understand why that happens. And how to solve the issue. Perhaps someone can give me a hint, what I'm doing wrong.

    Stefan

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread blocks gui

    How do you start that thread? Also make sure it doesn't touch the GUI.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QThread blocks gui

    You should call QThread::start() instead of QThread::run().
    J-P Nurmi

  4. #4
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread blocks gui

    Qt Code:
    1. class Install : public QThread,
    2. public paludis::InstallTask
    3. {
    4. Q_OBJECT
    5. public:
    6. Install(QObject* pobj,
    7. DatabaseView* main,
    8. const paludis::DepListOptions & options,
    9. paludis::tr1::shared_ptr<const paludis::DestinationsSet> destinations);
    10. ~Install() {}
    11. ...
    12.  
    13. };
    To copy to clipboard, switch view to plain text mode 


    I have to be more precise the next time, sorry. I'm using start() for starting the thread. The work is done in Install::run()->execute().
    The problem is, I have to pass a lot of text to a output window like a terminal like the gcc output and a lot more gentoo specific.
    Last edited by jacek; 26th October 2007 at 18:33. Reason: changed [qtclass] to [code]

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread blocks gui

    Quote Originally Posted by skoegl View Post
    The problem is, I have to pass a lot of text to a output window like a terminal like the gcc output and a lot more gentoo specific.
    Accessing a widget from a non-GUI thread is a Really Bad Thing(tm). Make sure you use queued connections instead.

  6. The following user says thank you to jacek for this useful post:

    skoegl (27th October 2007)

  7. #6
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread blocks gui

    @jacek:

    Ok, thanks. I've switched to SIGNAL/SLOT "message passing", and checked it into svn.

    @all:

    I tried with and without sending message (QString) to the main thread. The gui is still blocked while the thread is running. After the job is finished, the Gui is again responsively.

    How can I determine, what's the reason of this block?

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread blocks gui

    Quote Originally Posted by skoegl View Post
    How can I determine, what's the reason of this block?
    Try setting a breakpoint on QThread::start() to see whether you really start the thread.

Similar Threads

  1. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  2. QGraphicsScene and QThread
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2007, 09:32
  3. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  4. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55
  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.