Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#13621 closed Bug Report - General (fixed)

Convert from Qt foreach() macro to standard C++ range-for.

Reported by: David Hampton Owned by: David Hampton
Priority: major Milestone: 32.0
Component: MythTV - General Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

The use of foreach has caused some unexpected problems in the scheduler, which were chased down to containers detaching in the call to get the last item of the range. This detach guarantees that the current iterator is now invalid and the operation will eventually run off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++ range-for iteration, and (in almost all cases) use the qAsConst macro mark to the ranges as constant to prevent detaching of the data. There are a couple of places where adding the qAsConst macro throws a compiler error, so omit qAsConst in those instances. These cases all appear to occur with temporary lists, and this behavior is intentional on Qt's part (see https://doc.qt.io/qt-5/qtglobal.html#qAsConst-1).

Change History (7)

comment:1 Changed 5 months ago by David Hampton <mythtv@…>

In 5d9b74e7e6/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (plugins)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

comment:2 Changed 5 months ago by David Hampton <mythtv@…>

In f6e3a9598b/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (programs)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

comment:3 Changed 5 months ago by David Hampton <mythtv@…>

In b357f7d78/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (libs/libmythtv)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

comment:4 Changed 5 months ago by David Hampton <mythtv@…>

In 174e8f714/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (libs/libmythui)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

comment:5 Changed 5 months ago by David Hampton <mythtv@…>

In 11df0636c/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (libs/libmythbase)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

comment:6 Changed 5 months ago by David Hampton <mythtv@…>

Resolution: fixed
Status: assignedclosed

In c3cc79da1/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (libs)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Fixes #13621

comment:7 Changed 5 months ago by David Hampton <mythtv@…>

In f55f7ebe75/mythtv:

Convert from Qt foreach() macro to C++ standard range-for. (missed)

The use of foreach has caused some unexpected problems in the
scheduler, which were chased down to containers detaching in the call
to get the last item of the range. This detach guarantees that the
current iterator is now invalid and the operation will eventually run
off the end of the range.

The Qt company is also planning to remove the foreach/Q_FOREACH macro
in an (as yet unspecified) upcoming release.

Replace all instances of the foreach macro with a standard C++
range-for iteration, and (in almost all cases) use the qAsConst macro
mark to the ranges as constant to prevent detaching of the data.
There are a couple of places where adding the qAsConst macro throws a
compiler error, so omit qAsConst in those instances. These cases all
appear to occur with temporary lists, and this behavior is intentional
on Qt's part (see the Qt documentation).

Refs #13621

Note: See TracTickets for help on using tickets.