Skip to content

Commit 9604eda

Browse files
committed
Merge branch 'fix-qt5-cmdline-build-error'
* fix-qt5-cmdline-build-error: CommandLineModules: Fix build error related to ambiguous call to QStringRef::compare CommandLineModules: Fix Qt5 build error related to ResultStore
2 parents ab49e97 + 04631f5 commit 9604eda

5 files changed

Lines changed: 74 additions & 39 deletions

Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ QFutureInterface<ctkCmdLineModuleResult>::~QFutureInterface()
112112
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
113113
if (referenceCountIsOne())
114114
resultStore().clear();
115-
#else
115+
#elif QT_VERSION < QT_VERSION_CHECK(5,9,0)
116116
if (!derefT())
117117
resultStore().clear();
118+
#else
119+
if (!derefT())
120+
resultStore().clear<ctkCmdLineModuleResult>();
118121
#endif
119122

120123
if (!d->RefCount.deref())
@@ -139,7 +142,11 @@ QFutureInterface<ctkCmdLineModuleResult>::operator=(const QFutureInterface& othe
139142
other.refT();
140143
if (!derefT())
141144
#endif
145+
#if QT_VERSION < QT_VERSION_CHECK(5,9,0)
142146
resultStore().clear();
147+
#else
148+
resultStore().clear<ctkCmdLineModuleResult>();
149+
#endif
143150

144151
QFutureInterfaceBase::operator=(other);
145152

Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "ctkCmdLineModuleResult.h"
2828

2929
#include <QFutureInterface>
30-
#if (QT_VERSION < 0x50000)
30+
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
3131
#include <QtCore>
3232
#else
3333
#include <QtConcurrent>
@@ -88,16 +88,21 @@ class CTK_CMDLINEMODULECORE_EXPORT QFutureInterface<ctkCmdLineModuleResult> : pu
8888

8989
friend struct ctkCmdLineModuleFutureWatcherPrivate;
9090

91-
#if (QT_VERSION < 0x50000)
91+
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
9292
QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore()
9393
{ return static_cast<QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
9494
const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore() const
9595
{ return static_cast<const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
96-
#else
96+
#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
9797
QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore()
9898
{ return static_cast<QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
9999
const QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore() const
100100
{ return static_cast<const QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
101+
#else
102+
QtPrivate::ResultStoreBase &resultStore()
103+
{ return static_cast<QtPrivate::ResultStoreBase &>(resultStoreBase()); }
104+
const QtPrivate::ResultStoreBase &resultStore() const
105+
{ return static_cast<const QtPrivate::ResultStoreBase &>(resultStoreBase()); }
101106
#endif
102107

103108
ctkCmdLineModuleFutureInterfacePrivate* d;
@@ -110,10 +115,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResult(const ctkCmdL
110115
return;
111116
}
112117

113-
#if (QT_VERSION < 0x50000)
118+
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
114119
QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
115-
#else
120+
#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
116121
QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
122+
#else
123+
QtPrivate::ResultStoreBase &store = resultStore();
117124
#endif
118125

119126
if (store.filterMode()) {
@@ -138,10 +145,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResults(const QVecto
138145
return;
139146
}
140147

141-
#if (QT_VERSION < 0x50000)
148+
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
142149
QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
143-
#else
150+
#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
144151
QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
152+
#else
153+
QtPrivate::ResultStoreBase &store = resultStore();
145154
#endif
146155

147156
if (store.filterMode()) {
@@ -164,13 +173,21 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportFinished(const ctkCm
164173
inline const ctkCmdLineModuleResult &QFutureInterface<ctkCmdLineModuleResult>::resultReference(int index) const
165174
{
166175
QMutexLocker lock(mutex());
176+
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
167177
return resultStore().resultAt(index).value();
178+
#else
179+
return resultStore().resultAt(index).value<ctkCmdLineModuleResult>();
180+
#endif
168181
}
169182

170183
inline const ctkCmdLineModuleResult *QFutureInterface<ctkCmdLineModuleResult>::resultPointer(int index) const
171184
{
172185
QMutexLocker lock(mutex());
186+
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
173187
return resultStore().resultAt(index).pointer();
188+
#else
189+
return resultStore().resultAt(index).pointer<ctkCmdLineModuleResult>();
190+
#endif
174191
}
175192

176193
inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::results()
@@ -184,13 +201,19 @@ inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::r
184201
QList<ctkCmdLineModuleResult> res;
185202
QMutexLocker lock(mutex());
186203

187-
#if (QT_VERSION <= 0x50000)
204+
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
188205
QtConcurrent::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
189-
#else
206+
#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
190207
QtPrivate::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
208+
#else
209+
QtPrivate::ResultIteratorBase it = resultStore().begin();
191210
#endif
192211
while (it != resultStore().end()) {
212+
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
193213
res.append(it.value());
214+
#else
215+
res.append(it.value<ctkCmdLineModuleResult>());
216+
#endif
194217
++it;
195218
}
196219

Libs/CommandLineModules/Core/ctkCmdLineModuleParameterParsers_p.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@
2929

3030
namespace {
3131

32+
static int compare(const QStringRef& value1, const char* value2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
33+
{
34+
return value1.compare(QLatin1String(value2), cs);
35+
}
36+
3237
static bool parseBooleanAttribute(const QStringRef& attrValue)
3338
{
34-
if (attrValue.compare("true", Qt::CaseInsensitive) == 0 ||
35-
attrValue.compare("1") == 0)
39+
if (compare(attrValue, "true", Qt::CaseInsensitive) == 0 ||
40+
compare(attrValue, "1") == 0)
3641
{
3742
return true;
3843
}
@@ -79,43 +84,43 @@ struct ctkCmdLineModuleParameterParser
7984

8085
QStringRef name = xmlReader.name();
8186

82-
if (name.compare("name", Qt::CaseInsensitive) == 0)
87+
if (compare(name, "name", Qt::CaseInsensitive) == 0)
8388
{
8489
moduleParamPrivate->Name = xmlReader.readElementText().trimmed();
8590
}
86-
else if (name.compare("description", Qt::CaseInsensitive) == 0)
91+
else if (compare(name, "description", Qt::CaseInsensitive) == 0)
8792
{
8893
moduleParamPrivate->Description = xmlReader.readElementText().trimmed();
8994
}
90-
else if (name.compare("label", Qt::CaseInsensitive) == 0)
95+
else if (compare(name, "label", Qt::CaseInsensitive) == 0)
9196
{
9297
moduleParamPrivate->Label = xmlReader.readElementText().trimmed();
9398
}
94-
else if (name.compare("default", Qt::CaseInsensitive) == 0)
99+
else if (compare(name, "default", Qt::CaseInsensitive) == 0)
95100
{
96101
moduleParamPrivate->Default = xmlReader.readElementText().trimmed();
97102
}
98-
else if (name.compare("flag", Qt::CaseInsensitive) == 0)
103+
else if (compare(name, "flag", Qt::CaseInsensitive) == 0)
99104
{
100105
QString flag = xmlReader.readElementText().trimmed();
101106
if (flag.startsWith('-')) flag = flag.remove(0, 1);
102107
moduleParamPrivate->Flag = flag;
103108
moduleParamPrivate->FlagAliasesAsString = xmlReader.attributes().value("alias").toString();
104109
moduleParamPrivate->DeprecatedFlagAliasesAsString = xmlReader.attributes().value("deprecatedalias").toString();
105110
}
106-
else if (name.compare("longflag", Qt::CaseInsensitive) == 0)
111+
else if (compare(name, "longflag", Qt::CaseInsensitive) == 0)
107112
{
108113
QString longFlag = xmlReader.readElementText().trimmed();
109114
if (longFlag.startsWith('-')) longFlag = longFlag.remove(0, 1);
110115
moduleParamPrivate->LongFlag = longFlag;
111116
moduleParamPrivate->LongFlagAliasesAsString = xmlReader.attributes().value("alias").toString();
112117
moduleParamPrivate->DeprecatedLongFlagAliasesAsString = xmlReader.attributes().value("deprecatedalias").toString();
113118
}
114-
else if (name.compare("index", Qt::CaseInsensitive) == 0)
119+
else if (compare(name, "index", Qt::CaseInsensitive) == 0)
115120
{
116121
moduleParamPrivate->Index = xmlReader.readElementText().toInt();
117122
}
118-
else if (name.compare("channel", Qt::CaseInsensitive) == 0)
123+
else if (compare(name, "channel", Qt::CaseInsensitive) == 0)
119124
{
120125
moduleParamPrivate->Channel = xmlReader.readElementText().trimmed();
121126
}
@@ -134,15 +139,15 @@ struct ctkCmdLineModuleParameterParser
134139
while(xmlReader.readNextStartElement())
135140
{
136141
QStringRef constraintElem = xmlReader.name();
137-
if (constraintElem.compare("minimum", Qt::CaseInsensitive) == 0)
142+
if (compare(constraintElem, "minimum", Qt::CaseInsensitive) == 0)
138143
{
139144
moduleParamPrivate->Minimum = xmlReader.readElementText().trimmed();
140145
}
141-
else if (constraintElem.compare("maximum", Qt::CaseInsensitive) == 0)
146+
else if (compare(constraintElem, "maximum", Qt::CaseInsensitive) == 0)
142147
{
143148
moduleParamPrivate->Maximum = xmlReader.readElementText().trimmed();
144149
}
145-
else if (constraintElem.compare("step", Qt::CaseInsensitive) == 0)
150+
else if (compare(constraintElem, "step", Qt::CaseInsensitive) == 0)
146151
{
147152
moduleParamPrivate->Step = xmlReader.readElementText().trimmed();
148153
}
@@ -177,7 +182,7 @@ class ctkCmdLineModuleScalarVectorParameterParser : public ctkCmdLineModuleParam
177182
{
178183
QStringRef name = xmlReader.name();
179184

180-
if (name.compare("constraints", Qt::CaseInsensitive) == 0)
185+
if (compare(name, "constraints", Qt::CaseInsensitive) == 0)
181186
{
182187
return handleConstraintsElement(moduleParamPrivate, xmlReader);
183188
}
@@ -197,7 +202,7 @@ class ctkCmdLineModuleScalarParameterParser : public ctkCmdLineModuleMultiplePar
197202
{
198203
QStringRef name = xmlReader.name();
199204

200-
if (name.compare("constraints", Qt::CaseInsensitive) == 0)
205+
if (compare(name, "constraints", Qt::CaseInsensitive) == 0)
201206
{
202207
return handleConstraintsElement(moduleParamPrivate, xmlReader);
203208
}
@@ -217,7 +222,7 @@ class ctkCmdLineModuleEnumerationParameterParser : public ctkCmdLineModuleParame
217222
{
218223
QStringRef name = xmlReader.name();
219224

220-
if (name.compare("element", Qt::CaseInsensitive) == 0)
225+
if (compare(name, "element", Qt::CaseInsensitive) == 0)
221226
{
222227
moduleParamPrivate->Elements.push_back(xmlReader.readElementText().trimmed());
223228
return true;

Libs/CommandLineModules/Core/ctkCmdLineModuleXmlParser.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,39 +103,39 @@ void ctkCmdLineModuleXmlParser::handleExecutableElement()
103103
{
104104
QStringRef name = _xmlReader.name();
105105

106-
if (name.compare("category", Qt::CaseInsensitive) == 0)
106+
if (compare(name, "category", Qt::CaseInsensitive) == 0)
107107
{
108108
_md->d->Category = _xmlReader.readElementText().trimmed();
109109
}
110-
else if (name.compare("title", Qt::CaseInsensitive) == 0)
110+
else if (compare(name, "title", Qt::CaseInsensitive) == 0)
111111
{
112112
_md->d->Title = _xmlReader.readElementText().trimmed();
113113
}
114-
else if (name.compare("version", Qt::CaseInsensitive) == 0)
114+
else if (compare(name, "version", Qt::CaseInsensitive) == 0)
115115
{
116116
_md->d->Version = _xmlReader.readElementText().trimmed();
117117
}
118-
else if (name.compare("documentation-url", Qt::CaseInsensitive) == 0)
118+
else if (compare(name, "documentation-url", Qt::CaseInsensitive) == 0)
119119
{
120120
_md->d->DocumentationURL = _xmlReader.readElementText().trimmed();
121121
}
122-
else if (name.compare("license", Qt::CaseInsensitive) == 0)
122+
else if (compare(name, "license", Qt::CaseInsensitive) == 0)
123123
{
124124
_md->d->License = _xmlReader.readElementText().trimmed();
125125
}
126-
else if (name.compare("acknowledgements", Qt::CaseInsensitive) == 0)
126+
else if (compare(name, "acknowledgements", Qt::CaseInsensitive) == 0)
127127
{
128128
_md->d->Acknowledgements = _xmlReader.readElementText().trimmed();
129129
}
130-
else if (name.compare("contributor", Qt::CaseInsensitive) == 0)
130+
else if (compare(name, "contributor", Qt::CaseInsensitive) == 0)
131131
{
132132
_md->d->Contributor = _xmlReader.readElementText().trimmed();
133133
}
134-
else if (name.compare("description", Qt::CaseInsensitive) == 0)
134+
else if (compare(name, "description", Qt::CaseInsensitive) == 0)
135135
{
136136
_md->d->Description = _xmlReader.readElementText().trimmed();
137137
}
138-
else if (name.compare("parameters", Qt::CaseInsensitive) == 0)
138+
else if (compare(name, "parameters", Qt::CaseInsensitive) == 0)
139139
{
140140
this->handleParametersElement();
141141
}
@@ -159,11 +159,11 @@ void ctkCmdLineModuleXmlParser::handleParametersElement()
159159
{
160160
QStringRef name = _xmlReader.name();
161161

162-
if (name.compare("label", Qt::CaseInsensitive) == 0)
162+
if (compare(name, "label", Qt::CaseInsensitive) == 0)
163163
{
164164
group.d->Label = _xmlReader.readElementText().trimmed();
165165
}
166-
else if (name.compare("description", Qt::CaseInsensitive) == 0)
166+
else if (compare(name, "description", Qt::CaseInsensitive) == 0)
167167
{
168168
group.d->Description = _xmlReader.readElementText().trimmed();
169169
}

Libs/CommandLineModules/Core/ctkCmdLineModuleXmlProgressWatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ctkCmdLineModuleXmlProgressWatcherPrivate
129129
QString parent;
130130
if (!stack.empty()) parent = stack.back();
131131

132-
if (name.compare("module-root") != 0 && name.compare("module-snippet") != 0)
132+
if (name.compare(QLatin1String("module-root")) != 0 && name.compare(QLatin1String("module-snippet")) != 0)
133133
{
134134
stack.push_back(name.toString());
135135
}
@@ -177,7 +177,7 @@ class ctkCmdLineModuleXmlProgressWatcherPrivate
177177
if (!stack.empty()) parent = stack.back();
178178
}
179179

180-
if (parent.isEmpty() && name.compare("module-snippet") != 0)
180+
if (parent.isEmpty() && name.compare(QLatin1String("module-snippet")) != 0)
181181
{
182182
if (name.compare(FILTER_START, Qt::CaseInsensitive) == 0)
183183
{

0 commit comments

Comments
 (0)