Results 1 to 3 of 3

Thread: Need to do something in a safe place after all events done

  1. #1
    Join Date
    May 2013
    Posts
    320
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Need to do something in a safe place after all events done

    Hi!
    I have an event listener from a file watcher and it can happen during an event of a tree widget.
    The problem is I need to select a parent item if one selected item is deleted.
    If I do this action during the current tree event, I get a crash from Qt, surely a conflict of events.
    The only option I found is to emit a signal and connect to this signal in the same widget to ensure Qt will do the action in a safe place.
    Is there any other method, less hacky, to achieve the same result?
    Thanks!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,888
    Thanks
    275
    Thanked 796 Times in 785 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Need to do something in a safe place after all events done

    This sounds strange. Events should not be able to interrupt the processing of another event, but apparently that might be what is happening in this case.

    Your solution is not so hacky. Basically, by emitting a signal, you are ensuring that any slot connected to it will not be called until after processing of the current signal has completed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2013
    Posts
    320
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need to do something in a safe place after all events done

    On this case it's fine because I named the signal "DirectoryChanged" so an external widget could connect to it to know when a refresh will happen.
    So then I connected to this signal with a function named "InternalDirectoryChanged".
    But yes if it was a widget that would be exposed to an external team in a company then if you had to play with multiple signal and connect surely depending on the case it can be a solution not so clean and need good documentation.
    But I have to say I only met this special case here so maybe it's a very rare case.

Similar Threads

  1. GUI Thread is not safe
    By bds in forum Newbie
    Replies: 9
    Last Post: 25th October 2016, 16:35
  2. Thread safe or not
    By raj_iv in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2013, 21:28
  3. Storing the program data in a "safe place"
    By kremuwa in forum Qt Programming
    Replies: 9
    Last Post: 5th August 2010, 10:23
  4. thread-safe
    By babymonsta in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2010, 10:18
  5. Replies: 0
    Last Post: 3rd March 2009, 15:38

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.