Results 1 to 5 of 5

Thread: QThread , GUI freeze

  1. #1
    Join Date
    Jun 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QThread , GUI freeze

    Hi

    IM writing a mutithreaded GUI applcation.
    Im able to start a thread and from that thread Im posting a custom event. and my main window is catching that event and displaying a MEssage box

    But problem is GUI main window is not responding, it is freezing .

    What could be the problem.

    In my application, Im posting Custom event to QMainWindow instance, is it the problem.

    Im using Mythread->run() to satrt the thread, Could this be the problem ?

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread , GUI freeze

    try calling processEvents() after posting the events

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread , GUI freeze

    Hi,
    Im using Mythread->run() to satrt the thread, Could this be the problem ?
    I think that your problem is here. To start a Thread you have to call "start()", not "run()" method.
    This is because when you call start, a new Thread is created, it has its own memory space and its own code space. Then, the "start()" method makes the Thread to execute the "run()" method so the Thread is in the "run()" method.

    If you call "run()" instead of "start()" the Thread will never be created and the object that has called "run()" will execute the code of the method so a new Thread is not created. It is like the main Thread (GUI Thread) execute a infinite loop and so it is because your program freezes.

    It's like Java programming. Java has a Thread class like Qt and you have to redefine the "run()" method but have to call "start()" to let the OS to create the Thread and assign it its memory and code space.
    Last edited by ^NyAw^; 18th November 2006 at 12:09. Reason: updated contents
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jun 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread , GUI freeze

    My custom events are processed ???
    But Im not able to do anything with mouse or keyboard in the GUI Window(Thread)

  5. #5
    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 , GUI freeze

    You were already given the solution. You should call QThread::start() to begin the execution of the thread. QThread::start() does the actual work of starting a new thread and later then calls QThread::run() when appropriate, in the newly created thread. How do you expect a new thread to be started if you invoke run() directly? It won't magically begin a new thread. You are calling run() just like any other method. The GUI is frozen as long as your run() method keeps executing.
    J-P Nurmi

Similar Threads

  1. How can I get the thread ID out of QThread
    By Artschi in forum Qt Programming
    Replies: 9
    Last Post: 8th November 2017, 03:27
  2. QThread call-once semantics?
    By brcain in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2006, 21:25
  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. Replies: 4
    Last Post: 10th May 2006, 22:37
  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.