[Qt-interest] Local event loop

KIMURA, Hidetaka kimura at jig.jp
Thu Dec 9 02:03:51 CET 2010


Hi,

Is it possible to run a local event loop without firing events in the main
event loop? I want a MODAL event loop.

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LocalEventLoop.cc
Type: application/octet-stream
Size: 904 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101209/6240e9e7/attachment.obj 


More information about the Qt-interest-old mailing list