diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-11-30 22:23:37 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-12-02 11:10:09 +0000 |
commit | 07cbb94961f1c2a369feb4855de9ab6ae38c8a75 (patch) | |
tree | 15da817398873bad4bbc64204b1f9acf0bcc23ee /QtVsTools.Core | |
parent | e3147aedb1e4d6ed04b6411e07e6b1965494add8 (diff) |
Fix Object Reference Not Set to an instance of an object
This can happen if you try to change a solution's Qt version to
the "Default version" and there is no Qt version registered at all.
Fixes: QTVSADDINBUG-628
Task-number: QTVSADDINBUG-431
Change-Id: I988b493160b38a0a167c5b9b81663ad251a3a75e
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Diffstat (limited to 'QtVsTools.Core')
-rw-r--r-- | QtVsTools.Core/QtProject.cs | 24 | ||||
-rw-r--r-- | QtVsTools.Core/Resources.resx | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/QtVsTools.Core/QtProject.cs b/QtVsTools.Core/QtProject.cs index 0977e530..f19f7252 100644 --- a/QtVsTools.Core/QtProject.cs +++ b/QtVsTools.Core/QtProject.cs @@ -3163,20 +3163,26 @@ namespace QtVsTools.Core { newProjectCreated = false; var versionManager = QtVersionManager.The(); - var viOld = versionManager.GetVersionInfo(oldVersion); var viNew = versionManager.GetVersionInfo(newVersion); + if (viNew == null) { + Messages.DisplayErrorMessage(SR.GetString("CannotChangeQtVersion")); + return false; + } + string vsPlatformNameNew = viNew.GetVSPlatformName(); + var viOld = versionManager.GetVersionInfo(oldVersion); string vsPlatformNameOld = null; if (viOld != null) vsPlatformNameOld = viOld.GetVSPlatformName(); - var vsPlatformNameNew = viNew.GetVSPlatformName(); - var bRefreshMocSteps = (vsPlatformNameNew != vsPlatformNameOld); + + var refreshMocSteps = (vsPlatformNameNew != vsPlatformNameOld); + var platformChanged = (vsPlatformNameNew != vsPlatformNameOld); try { - if (vsPlatformNameOld != vsPlatformNameNew) { + if (platformChanged) { if (!SelectSolutionPlatform(vsPlatformNameNew) || !HasPlatform(vsPlatformNameNew)) { CreatePlatform(vsPlatformNameOld, vsPlatformNameNew, viOld, viNew, ref newProjectCreated); - bRefreshMocSteps = false; + refreshMocSteps = false; UpdateMocSteps(QtVSIPSettings.GetMocDirectory(envPro)); } } @@ -3194,15 +3200,15 @@ namespace QtVsTools.Core return false; } - // We have to delete the generated files because of - // major differences between the platforms or Qt-Versions. - if (vsPlatformNameOld != vsPlatformNameNew || viOld.qtPatch != viNew.qtPatch + // We have to delete the generated files because of major + // differences between the platforms or Qt-Versions. + if (platformChanged || viOld.qtPatch != viNew.qtPatch || viOld.qtMinor != viNew.qtMinor || viOld.qtMajor != viNew.qtMajor) { DeleteGeneratedFiles(); Clean(); } - if (bRefreshMocSteps) + if (refreshMocSteps) RefreshMocSteps(); SetQtEnvironment(newVersion); diff --git a/QtVsTools.Core/Resources.resx b/QtVsTools.Core/Resources.resx index 4abadd7b..cdf3b7a7 100644 --- a/QtVsTools.Core/Resources.resx +++ b/QtVsTools.Core/Resources.resx @@ -324,4 +324,7 @@ Select 'Yes' to overwrite, select 'No' to keep the existing file and automatical <data name="WaitDialogRefreshMoc" xml:space="preserve"> <value>Updating moc steps...</value> </data> + <data name="CannotChangeQtVersion" xml:space="preserve"> + <value>The Qt version of at least one project cannot be changed.</value> + </data> </root>
\ No newline at end of file |