Results 1 to 4 of 4

Thread: Main Event Loop response to all signals

  1. #1
    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 Main Event Loop response to all signals

    Hi,

    I have a Thread that emits "results" that have to be computed in the main Thread. The Thread emits a signal like "mySignal(bool)" so the result of the processing is passed to the main Thread. The problem is that the Main Event Loop joins a group of those signals into one slot call because the signals contain the same value:

    Qt Code:
    1. true
    2. true
    3. true
    4. true
    5. ...
    6. true
    7. false
    8. true
    9. true
    10. true
    11. ...
    To copy to clipboard, switch view to plain text mode 

    Using a random value as a second argument will force the Main Event Loop to call the slot for every signal emitted?

    I need this because in the Main Thread there is a IO card that must activate or deactivate some Outputs. For the complexity of the application it can't be done directly on the worker thread as could be there more than a thread that give results and then this results are joined and finally must activate the Outputs according this joined result.

    Thanks,
    Òscar Llarch i Galán

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

    Default Re: Main Event Loop response to all signals

    You can always use QCoreApplication::postEvent() and QObject::customEvent() instead of signals.
    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
    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: Main Event Loop response to all signals

    Hi,

    I have tryied but the application was very slow. Maybe I did it wrong. I have deleted the code but it was like this:

    worker thread
    Qt Code:
    1. ...
    2. QCoreApplication::postEvent(myObject,new myEvent());
    3. ...
    To copy to clipboard, switch view to plain text mode 

    myClass
    Qt Code:
    1. bool myClass::event(myEvent *event)
    2. {
    3. ...
    4. return true;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Hi again,

    I have rewrited the code using "QCoreApplication:ostEvent()" and it works fine. The application works as expected.

    Using "QCoreApplication:ostEvent()", all the events are processed?

    So, using this way I don't need to use mutexes to lock the main and the worker threads about results.

    Thanks,
    Last edited by ^NyAw^; 3rd October 2013 at 12:15.
    Òscar Llarch i Galán

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

    Default Re: Main Event Loop response to all signals

    You are supposed to use customEvent() and not event().
    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.


Similar Threads

  1. Replies: 3
    Last Post: 10th June 2010, 08:35
  2. Replies: 10
    Last Post: 15th January 2010, 14:35
  3. How to log returning control back to the main event loop?
    By piotr.dobrogost in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2009, 09:57
  4. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10
  5. How to bind Qt3 and Qt4 main event loop.
    By Opilki_Inside in forum Qt Programming
    Replies: 7
    Last Post: 10th May 2006, 08:04

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.