Skip to content

Commit 410e097

Browse files
committed
fix compiler warnings
1 parent 2677304 commit 410e097

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

omodsim/modbusserver.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,45 @@ QVariant ModbusServer::value(int option, int serverAddress) const
142142
///
143143
bool ModbusServer::setValue(int option, const QVariant &newValue, int serverAddress)
144144
{
145+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
145146
#define CHECK_INT_OR_UINT(val) \
146147
do { \
147-
const int type = val.userType(); \
148-
if (type != QMetaType::Int && type != QMetaType::UInt) \
149-
return false; \
148+
if ((val.typeId() != QMetaType::Int) && (val.typeId() != QMetaType::UInt)) \
149+
return false; \
150150
} while (0)
151151

152152
#define CHECK_BOOL(val) \
153-
do { \
154-
if (!val.canConvert(QMetaType::Bool)) \
153+
do { \
154+
if(val.metaType().id() != QMetaType::Bool) \
155155
return false; \
156156
} while (0)
157157

158158
#define CHECK_BYTEARRAY(val) \
159159
do { \
160-
if (!val.canConvert(QMetaType::QByteArray)) \
160+
if(val.metaType().id() != QMetaType::QByteArray) \
161161
return false; \
162+
} while (0)
163+
#else
164+
// Qt5
165+
#define CHECK_INT_OR_UINT(val) \
166+
do { \
167+
if ((val.type() != QVariant::Int) && (val.type() != QVariant::UInt)) \
168+
return false; \
162169
} while (0)
163170

171+
#define CHECK_BOOL(val) \
172+
do { \
173+
if (val.type() != QVariant::Bool) \
174+
return false; \
175+
} while (0)
176+
177+
#define CHECK_BYTEARRAY(val) \
178+
do { \
179+
if (val.type() != QVariant::ByteArray) \
180+
return false; \
181+
} while (0)
182+
#endif
183+
164184
switch (option) {
165185
case DiagnosticRegister:
166186
CHECK_INT_OR_UINT(newValue);

omodsim/modbustcpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void ModbusTcpServer::close()
242242
if (_server->isListening())
243243
_server->close();
244244

245-
for (auto socket : qAsConst(_connections))
245+
for (auto socket : std::as_const(_connections))
246246
socket->disconnectFromHost();
247247

248248
setState(QModbusDevice::UnconnectedState);

0 commit comments

Comments
 (0)