[Qt-interest] Local event loop

KIMURA, Hidetaka kimura at jig.jp
Fri Dec 10 01:25:48 CET 2010


Thanks guys. But I do not want to run both main and local event loop. I
want to block main event loop. I want to download a file without running
any event in main event loop. But as shown in my sample code, timer
events have fired in eventLoop.exec().

On Thu, 9 Dec 2010 09:39:17 -0400
Brian McKinnon <bpmckinnon.qt at gmail.com> wrote:

> If I understand your problem correctly then I think you may want to look at
> a QThread.  Each QThread provides its own event loop without blocking the
> main event loop.
> 
> On Thu, Dec 9, 2010 at 4:46 AM, Kai Koehne <kai.koehne at nokia.com> wrote:
> 
> > On 12/9/2010 2:03 AM, ext KIMURA, Hidetaka wrote:
> >  > Hi,
> >  >
> >  > Is it possible to run a local event loop without firing events in the
> > main
> >  > event loop? I want a MODAL event loop.
> >
> > I doubt that the main event loop is actually delivering the timeout
> > event (since it's blocked), but that the sub-event loop is delivering it.
> >
> > You can pose some restrictions on the types of events being delivered in
> > an event loop (see
> > http://doc.qt.nokia.com/4.7/qeventloop.html#ProcessEventsFlag-enum ).
> > Anyhow, it seems that this won't help you for your specific problem.
> >
> > Regards
> >
> > Kai Koehne
> >
> >  > Here is a sample code that download a HTML in local event loop. I expect
> >  > that no timeout fires in the local event loop's exec(). This code is
> >  > similar to Qt Quarterly's sample.
> >  >
> >  >
> >
> > http://doc.trolltech.com/qq/qq27-responsive-guis.html#waitinginalocaleventloop
> >  >
> >  > #include<QCoreApplication>
> >  > #include<QNetworkAccessManager>
> >  > #include<QNetworkReply>
> >  > #include<QNetworkRequest>
> >  > #include<QTimer>
> >  > #include<QUndoCommand>
> >  >
> >  > int main(int argc, char** argv) {
> >  >      QCoreApplication app(argc, argv);
> >  >      {
> >  >              // The timer will not fire in a local event loop.
> >  >              QUndoStack stack;
> >  >              for (int i = 0; i<  100; ++i) {
> >  >                      stack.push(new QUndoCommand(QString("%1").arg(i)));
> >  >                      QTimer::singleShot(i * 10,&stack, SLOT(undo()));
> >  >              }
> >  >
> >  >              QNetworkRequest request(QUrl("http://example.com/"));
> >  >              QNetworkReply* reply;
> >  >              QNetworkAccessManager manager;
> >  >
> >  >              printf("stack index = %d (should be 100)\n",
> > stack.index());
> >  >              {
> >  >                      // Entering local event loop
> >  >                      QEventLoop eventLoop;
> >  >
> >  >                      eventLoop.connect(&manager,
> > SIGNAL(finished(QNetworkReply*)),
> > SLOT(quit()));
> >  >                      reply = manager.get(request);
> >  >                      eventLoop.exec();
> >  >              }
> >  >              printf("stack index = %d (should be 100)\n",
> > stack.index());
> >  >      }
> >  >      return 0;
> >  > }
> >  >
> >  >
> >  > -------
> >  > KIMURA, Hide - kimura at jig.jp
> >
> >
> > --
> > Kai Koehne
> > Software Engineer
> > Nokia, Qt Development Frameworks
> >
> > Nokia gate5 GmbH
> > Firmensitz: Invalidenstr. 117, 10115 Berlin, Germany
> > Registergericht: Amtsgericht Charlottenburg, Berlin: HRB 106443 B
> > Umsatzsteueridentifikationsnummer: DE 812 845 193
> > Geschäftsführer: Dr. Michael Halbherr, Karim Tähtivuori
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >

-------
KIMURA, Hide - kimura at jig.jp




More information about the Qt-interest-old mailing list