Results 1 to 15 of 15

Thread: window freezed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: window freezed

    Ok,

    I've read the complete project and this method is called from 2 differents callback methods from two different objects.

    ¿Is it possible that i need a mutex in the method shared by the 2 callbacks?

    (sorry for my mistake at explain my problem)

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

    Default Re: window freezed

    You don't need any mutexes if your program does not have more than one thread. So far we have seen no evidence of more than one thread in your program.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: window freezed

    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.

    If this two callback methods, use the method that writes in the textfields, i think i need to use a mutex to prevent...

    Am i in an error?

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

    Default Re: window freezed

    Quote Originally Posted by jrodway View Post
    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.
    I don't know what is the origin of those callbacks but if this is purely Qt code, then there are no threads involved. If there are threads involved, then you can't call any UI-related code from within those callbacks.
    Last edited by wysota; 3rd September 2014 at 14:38.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: window freezed

    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.
    Signals and slots within the GUI do not use threads. I don't think you really understand what "thread" means. In the Qt GUI, everything is queued, and events (including slots) are executed in a sequence. It is impossible for two "messages" (whatever those are) to be received at the same time. One will be received and put into the event queue first, followed by the second one, and the code for them will be executed in the order they were put into the queue.

    The handlers for some events (like paintEvent()) will execute the event only once and remove extra copies from the queue to avoid unnecessary processing, but in general things in the event queue are executed in first-in, first-out order.

  6. #6
    Join Date
    Jul 2007
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: window freezed

    I'm sorry, but i use only qt code with the ui. The rest of the application use Threads posix.

    I've got two threads in the main application that try to modify the textfields of the ui. is it possible that i need a mutex to avoid the freeze of the window?

    Thanks for your opinions.

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

    Default Re: window freezed

    Quote Originally Posted by jrodway View Post
    I've got two threads in the main application that try to modify the textfields of the ui. is it possible that i need a mutex to avoid the freeze of the window?
    No, you cannot access any QObject from any thread other than the thread it belongs to (meaning the application thread in case of Qt widgets) and there is no way to work around this using mutexes. If there are threads involved, you need to change your application design so that those extra threads post messages to the UI thread and then the UI thread modifies state of the wigdets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: window freezed

    I think the signal/slot connection in the code above should take care of crossing the thread boundary properly, i.e. it should become a Qt::QueuedConnection.
    But you can try to specify that explictly as the fifth argument to connect().

    Independently I would strongly recommend to make the char* -> QString conversion somewhere before emitting the signal, so that the thread which created the array can delete it as well.

    And, as mentioned earlier, it should do that using the correct delete operator.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 14th January 2013, 08:07
  2. Replies: 6
    Last Post: 9th November 2011, 05:31
  3. Replies: 2
    Last Post: 17th February 2011, 13:30
  4. Make first column freezed in QTableView
    By gutiory in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2010, 07:53
  5. Replies: 11
    Last Post: 4th June 2008, 08:22

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