OSDN Git Service

Don't crash if the restored default version index is out of range
authordt <qtc-committer@nokia.com>
Thu, 29 Oct 2009 13:07:22 +0000 (14:07 +0100)
committerdt <qtc-committer@nokia.com>
Thu, 29 Oct 2009 13:09:24 +0000 (14:09 +0100)
src/plugins/qt4projectmanager/qtversionmanager.cpp

index 5774b8d..f28ec89 100644 (file)
@@ -141,6 +141,23 @@ QtVersionManager::QtVersionManager()
     writeVersionsIntoSettings();
 
     updateDocumentation();
+
+    if (m_defaultVersion > m_versions.size() || m_defaultVersion < 0) {
+        // Invalid default version, correct that...
+        for(int i = 0; i < m_versions.size(); ++i) {
+            QtVersion *version = m_versions.at(i);
+            if (version->isAutodetected() && version->autodetectionSource() == PATH_AUTODETECTION_SOURCE && version->isValid()) {
+                m_defaultVersion = i;
+                break;
+            }
+        }
+    }
+
+    if (m_defaultVersion > m_versions.size() || m_defaultVersion < 0) {
+        // Still invalid? Use the first one
+        m_defaultVersion = 0;
+    }
+
     // cannot call from ctor, needs to get connected extenernally first
     QTimer::singleShot(0, this, SLOT(updateExamples()));
 }