0

I declare QEventloop class property:

   class myClass: public QObject
    {
        Q_OBJECT
        public:
            explicit QZXingFilterRunnable(QZXingFilter * filter)
    // ...
        private:
            //  ...
            QEventLoop myEvt;
    };

and then in one of class methods, I want to set event loop for a specific code segment , I don't understand how QEventloop knows its boundary, this is the code:

myClass::myMethod(void*)
    : QObject(nullptr)

{
// Code Block1 ....
// ....
// ...code Block2
// ...
// Code Block to be looped by QEventloop
    // this is the block I want in loop
    timer.setSingleShot(true);
    timer.setInterval(100);
    QObject::connect(&timer, SIGNAL(timeout()), &something, SLOT(cancel()));
    QObject::connect(&timer, SIGNAL(timeout()),  &myEvt, SLOT(quit()));
    QObject::connect(&watcher, SIGNAL(finished()), &myEvt, SLOT(quit()));
     QtConcurrent::run(this,&myClass::myMethod,*param);
    timer.start(); 
    myEvt.exec();  // How do MyEvt know which code block is to be in loop ?
    //
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
  • 1
    What do you mean by "boundary" ? An event-loop will just wait and process the events incoming (signal-slots or events), it does not matter which code block is starting it, all events will be processed. – ymoreau Sep 27 '17 at 14:32
  • Thank you, I was reading a reference at https://www.qtdeveloperdays.com/2013/sites/default/files/presentation_pdf/Qt_Event_Loop.pdf , page 18 made me think of boundary (Blocking). Coming to your clarification, the phrase "All events" is vague ... all events in a method ? in an object? .. or in the Application ? which Signals/Slots ... All in the application ?? or those declared in this object ? Consider also for instance my example, do you mean that the Signals/slots I declared, have a limited life time until the QEventloop quits ? is this the purpose of QEventloop? – Mohammad Kanan Sep 27 '17 at 16:55
  • 1
    Reading about the [Qt main event loop](http://doc.qt.io/qt-5/qcoreapplication.html#the-event-loop-and-event-handling) and [signals-slots](http://doc.qt.io/qt-5/signalsandslots.html) could help. Events and signals are global to the application, it is all about who is listening to them (connecting to them), the event loop will handle+queue them and then dispatch to the *QObject*s that registered for them. Signals and QEvent have subtle differences though, but start with the big picture to understand the Qt system. – ymoreau Sep 28 '17 at 08:28
  • Thank you. I have some basic insight in Qt, some parts are not well documented. That still needs further search! But what Qt states at http://doc.qt.io/qt-5/qeventloop.html#details , is "At any time, you can create a QEventLoop object and call exec() on it to start a local event loop" , this is what confuses me , what do they mean by "local event loop"! this is what I am missing. – Mohammad Kanan Sep 28 '17 at 13:50
  • My conclusion, back to the example, since I declared and initialized Qeventloop evt in the class constr, therefore, its scope would be the class object. a local loop would be bounded between declaring it and exiting { QEventloop evt ; .........code........... evt.exec() ; this is what i was looking for. I will adapt this concept unless otherwise compiler/runtime say no :) – Mohammad Kanan Sep 28 '17 at 15:09
  • 1
    The scope of your variable is indeed what you said. But you have to understand the handling of events *has no scope at all*. You will still process events/signals coming from your whole application here. That means if you have a network class somewhere else sending events/signals, they will get processed by your `myEvt.exec();`, in the middle of your *blocking loop*. – ymoreau Sep 29 '17 at 07:43
  • Thanks a lot, yes totally agree, global wide handling is not blocked/masked, agree. On the other hand, which I was actually my question: once local event loop lifetime expires (by calling quit) .. processing is handled to parent/global event loop and all events / signals maintained within local loop scope would be masked from parent/global event loop ... they wont be processed anymore i.e they only have a local scope. this is my conclusion. – Mohammad Kanan Sep 29 '17 at 13:32

0 Answers0