Skip to content

Commit 4b066c2

Browse files
Qt Designer: Add a command line option for the Qt version for form serialization
This mainly serves for testing. Pick-to: 6.8 6.7 Task-number: PYSIDE-2492 Task-number: QTBUG-118473 Task-number: QTBUG-127179 Change-Id: I62e4c002fe1f84d6873f8adc559d61c9553dc599 Reviewed-by: Eike Ziller <[email protected]>
1 parent 6dd86a6 commit 4b066c2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/designer/src/designer/qdesigner.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "qdesigner_settings.h"
99
#include "qdesigner_workbench.h"
1010
#include "mainwindow.h"
11-
11+
#include <QtDesigner/abstractintegration.h>
12+
#include <QtDesigner/abstractformeditor.h>
1213
#include <qdesigner_propertysheet_p.h>
1314

1415
#include <QtGui/qevent.h>
@@ -27,9 +28,13 @@
2728
#include <QtCore/qdebug.h>
2829
#include <QtCore/qcommandlineparser.h>
2930
#include <QtCore/qcommandlineoption.h>
31+
#include <QtCore/qversionnumber.h>
32+
#include <QtCore/qvariant.h>
3033

3134
#include <QtDesigner/QDesignerComponents>
3235

36+
#include <optional>
37+
3338
QT_BEGIN_NAMESPACE
3439

3540
using namespace Qt::StringLiterals;
@@ -137,6 +142,7 @@ struct Options
137142
QStringList files;
138143
QString resourceDir{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};
139144
QStringList pluginPaths;
145+
std::optional<QVersionNumber> qtVersion;
140146
bool server{false};
141147
quint16 clientPort{0};
142148
bool enableInternalDynamicProperties{false};
@@ -168,6 +174,11 @@ static inline QDesigner::ParseArgumentsResult
168174
u"path"_s);
169175
parser.addOption(pluginPathsOption);
170176

177+
const QCommandLineOption qtVersionOption(u"qt-version"_s,
178+
u"Qt Version for writing .ui files"_s,
179+
u"version"_s);
180+
parser.addOption(qtVersionOption);
181+
171182
parser.addPositionalArgument(u"files"_s,
172183
u"The UI files to open."_s);
173184

@@ -197,6 +208,9 @@ static inline QDesigner::ParseArgumentsResult
197208
for (const auto &pluginPath : pluginPathValues)
198209
options->pluginPaths.append(pluginPath.split(QDir::listSeparator(), Qt::SkipEmptyParts));
199210

211+
if (parser.isSet(qtVersionOption))
212+
options->qtVersion = QVersionNumber::fromString(parser.value(qtVersionOption));
213+
200214
options->enableInternalDynamicProperties = parser.isSet(internalDynamicPropertyOption);
201215
options->files = parser.positionalArguments();
202216
return QDesigner::ParseArgumentsSuccess;
@@ -250,6 +264,15 @@ QDesigner::ParseArgumentsResult QDesigner::parseCommandLineArguments()
250264
if (m_workbench->formWindowCount() > 0)
251265
suppressNewFormShow = true;
252266

267+
if (options.qtVersion.has_value()) {
268+
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
269+
m_workbench->core()->integration()->setQtVersion(options.qtVersion.value());
270+
#else
271+
auto version = QVariant::fromValue(options.qtVersion.value());
272+
m_workbench->core()->integration()->setProperty("qtVersion", version);
273+
#endif
274+
}
275+
253276
// Show up error box with parent now if something went wrong
254277
if (m_initializationErrors.isEmpty()) {
255278
if (!suppressNewFormShow)

0 commit comments

Comments
 (0)