diff --git a/src/shared/proparser/qmakeevaluator.cpp b/src/shared/proparser/qmakeevaluator.cpp
index 2f732161c31dde625383db5ac46e23f1b352baa4..d08282d4b1ef57c1c44882a7b4abdac8530596da 100644
--- a/src/shared/proparser/qmakeevaluator.cpp
+++ b/src/shared/proparser/qmakeevaluator.cpp
@@ -117,6 +117,7 @@ void QMakeEvaluator::initStatics()
     statics.strhost_build = QLatin1String("host_build");
     statics.strTEMPLATE = ProKey("TEMPLATE");
     statics.strQMAKE_PLATFORM = ProKey("QMAKE_PLATFORM");
+    statics.strQMAKESPEC = ProKey("QMAKESPEC");
 #ifdef PROEVALUATOR_FULL
     statics.strREQUIRES = ProKey("REQUIRES");
 #endif
@@ -932,6 +933,12 @@ void QMakeEvaluator::visitProVariable(
         setTemplate();
     else if (varName == statics.strQMAKE_PLATFORM)
         m_featureRoots = 0;
+    else if (varName == statics.strQMAKESPEC) {
+        if (!values(varName).isEmpty()) {
+            m_qmakespec = values(varName).first().toQString();
+            m_featureRoots = 0;
+        }
+    }
 #ifdef PROEVALUATOR_FULL
     else if (varName == statics.strREQUIRES)
         checkRequirements(values(varName));
@@ -1153,7 +1160,7 @@ bool QMakeEvaluator::loadSpecInternal()
         m_qmakespec = orig_spec.toQString();
 #  endif
 #endif
-    valuesRef(ProKey("QMAKESPEC")) << ProString(m_qmakespec);
+    valuesRef(ProKey("QMAKESPEC")) = ProString(m_qmakespec);
     m_qmakespecName = IoUtils::fileName(m_qmakespec).toString();
     // This also ensures that m_featureRoots is valid.
     if (evaluateFeatureFile(QLatin1String("spec_post.prf")) != ReturnTrue)
diff --git a/src/shared/proparser/qmakeevaluator_p.h b/src/shared/proparser/qmakeevaluator_p.h
index 50c063be895b1dbdac4081d27339875a06a15c3c..078c1cd89cd84cb2847941f5c9c87465b7a71320 100644
--- a/src/shared/proparser/qmakeevaluator_p.h
+++ b/src/shared/proparser/qmakeevaluator_p.h
@@ -79,6 +79,7 @@ struct QMakeStatics {
     QString strhost_build;
     ProKey strTEMPLATE;
     ProKey strQMAKE_PLATFORM;
+    ProKey strQMAKESPEC;
 #ifdef PROEVALUATOR_FULL
     ProKey strREQUIRES;
 #endif