[Qt-interest] Local event loop

Brian McKinnon bpmckinnon.qt at gmail.com
Thu Dec 9 14:39:17 CET 2010


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101209/8f6989f5/attachment.html 


More information about the Qt-interest-old mailing list