diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp
index 9ed0256ffd9a4d4feffd81387c0b44c9a3b6ae0b..4e6dd924f3d63937cb29b453d3fe5d6f5c015159 100644
--- a/tools/qmlscene/main.cpp
+++ b/tools/qmlscene/main.cpp
@@ -291,7 +291,7 @@ static bool checkVersion(const QUrl &url)
 
 static void displayFileDialog(Options *options)
 {
-#ifdef QT_WIDGETS_LIB
+#if defined(QT_WIDGETS_LIB) && !defined(QT_NO_FILEDIALOG)
     QString fileName = QFileDialog::getOpenFileName(0, "Open QML file", QString(), "QML Files (*.qml)");
     if (!fileName.isEmpty()) {
         QFileInfo fi(fileName);