[Qt-interest] Local event loop

Kai Koehne kai.koehne at nokia.com
Thu Dec 9 09:46:44 CET 2010


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



More information about the Qt-interest-old mailing list