widgets: Fix potential detach of non-const Qt containers
ClosedPublic

Authored by patrickelectric on Jun 28 2018, 12:10 PM.

Details

Summary

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>

core: Fix potential detach of non-const Qt containers

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>

Diff Detail

Repository
R232 AtCore
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
patrickelectric requested review of this revision.Jun 28 2018, 12:10 PM
patrickelectric created this revision.

Why ? and why only for these two

Why ? and why only for these two

From: https://www.kdab.com/goodbye-q_foreach/

Last, not least, if your container is a non-const lvalue, you have two choices: Make the container const, or, if that doesn’t work, use std::as_const() (new in C++17, but easily implemented yourself, if required) or qAsConst() (new in Qt 5.7) to cast to const:

There are two more instances you can do this with in atcore.cpp

line 245

for (const QSerialPortInfo &serialPortInfo : serialPortInfoList) {

and line 484

for (const QString &f : files) {

They are const variables inside the scope.

rizzitello accepted this revision.Jun 28 2018, 12:57 PM
This revision is now accepted and ready to land.Jun 28 2018, 12:57 PM
This revision was automatically updated to reflect the committed changes.