分类: 嵌入式
2014-09-14 22:21:53
Detailed DescriptionThe QEventLoop class provides a means of entering and leaving an event loop. At any time, you can create a QEventLoop object and call () on it to start a local event loop. From within the event loop, calling () will force () to return. 翻译: QEventLoop类为我们提供了一种进入和退出事件循环的方法。 在任何时候,你都可以创建一个QEventLoop实例,并通过调用exec()来启动一个事件循环。在循环期间,主动调用exit()可以使exec()强制返回。 |
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QEventLoop loop; manager = new QNetworkAccessManager(this); QNetworkRequest request; request.setUrl(QUrl("http://www.350351.com/templets/default/css/images/logo.png")); QNetworkReply *reply = manager->get(request); connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));//关键之处1 loop.exec();//关键之处2
QPixmap pix; QByteArray data = reply->readAll(); pix.loadFromData(data, "PNG"); pix.save("./0001.png", "PNG", 100); ui->textEdit->append(" src=./0001.png>"); } |