diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
index abfe769635cf325b4832df359b78ec34648166a4..9aae0fd1a150b7092985a47ce059ccdc0ccbf9c1 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
@@ -496,10 +496,12 @@ void StatesEditorView::clearModelStates()
     if (debug)
         qDebug() << __FUNCTION__;
 
-    // For m_modelStates / m_editorModel, i=0 is base state
-    while (m_modelStates.size()) {
-        m_modelStates.removeFirst();
-        m_editorModel->removeState(0);
+
+    // Remove all states
+    const int modelStateCount = m_modelStates.size();
+    for (int i = 0; i < modelStateCount; ++i) {
+        m_modelStates.removeAt(i);
+        m_editorModel->removeState(i);
     }
 }