#include #include #include #include #include #include #include #include #define INTERACTIVE_TEST 1 class Viewer : public QWidget { Q_OBJECT public: Viewer(QWidget *parent = 0) : QWidget(parent) { // setting icon database path [1] QWebSettings::globalSettings()->setIconDatabasePath(qApp->applicationDirPath()); m_webView = new QWebView(this); m_webView->setObjectName("webView"); QMetaObject::connectSlotsByName(this); // meta refresh with 0 second delay and base URL with favicon.ico [2] m_webView->setHtml("", QUrl("http://www.webkit.org/")); QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(m_webView); // the combination of [1] and [2] results in loadFinished event with ok = false } private slots: void on_webView_loadFinished(bool ok) { // for some reason, ok = false because of [1] if (!ok) { #if INTERACTIVE_TEST // crash after clicking OK in blocking modal message box QMessageBox::critical(this, tr("Error"), tr("Failed to load URL.")); #else // block while processing events for a bit to simulate showing blocking modal dialog and clicking OK QEventLoop ev; QTimer::singleShot(1000, &ev, SLOT(quit())); ev.exec(); #endif } #if !INTERACTIVE_TEST qApp->quit(); #endif } private: QWebView *m_webView; }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); Viewer v; #if INTERACTIVE_TEST v.show(); #endif return a.exec(); }