Qt foreach misuses

Hi List,

Albert Astals Cid said on #kalzium that he saw misuses of Qt’s “foreach” in
libavogadro. Understandably, he’s not eager to fix them in kalzium’s snapshot
of libavogadro, but he suggested that I pointed anybody interested to his
blog post on this subject:

Hope this interests anybody,

Benoit

And here are some examples:

[23:34] src/glwidget.cpp: foreach( QString path,
pluginPaths ) {
[23:34] src/glwidget.cpp: foreach( QString fileName,
dir.entryList( QDir::Files ) ) {
[23:34] src/toolgroup.cpp: foreach (QString path, pluginPaths)
[23:34] src/toolgroup.cpp: foreach (QString fileName,
dir.entryList(QDir::Files)) {
[23:35] not sure if GLHit is a basic type or an object
[23:35] if it’s an object/struct
[23:35] src/glwidget.cpp: foreach( GLHit hit, chits )
[23:35] ok, sending a followup with that !
[23:35] it’s an object
[23:35] so that GLHit need to be const & too
[23:36] by object you mean QObject ??
[23:36] no no
[23:36] i mean something not int/double/char
[23:36] ah ok
[23:36] non-POD
[23:36] yeah

On Friday 25 April 2008 23:32:59 Benoît Jacob wrote:

Hi List,

Albert Astals Cid said on #kalzium that he saw misuses of Qt’s “foreach” in
libavogadro. Understandably, he’s not eager to fix them in kalzium’s
snapshot of libavogadro, but he suggested that I pointed anybody interested
to his blog post on this subject:

TSDgeos' blog: Q_FOREACH is your friend

Hope this interests anybody,

Benoit

On Friday 25 April 2008 23:32:59 Benoît Jacob wrote:

Hi List,

Albert Astals Cid said on #kalzium that he saw misuses of Qt’s "foreach"
in libavogadro. Understandably, he’s not eager to fix them in kalzium’s
snapshot of libavogadro, but he suggested that I pointed anybody
interested to his blog post on this subject:

http://tsdgeos.blogspot.com/2008/04/qforeach-is-your-friend.html

Hope this interests anybody,

Benoit

OK - I made the changes to the places he pointed out. I had a quick scan
around and couldn’t spot similar stuff but we use foreach loops in a lot of
places. I will fix these as I see them. I am always in favour of making
Avogadro more efficient where we can :slight_smile:

Thanks for pointing it out - I had read the blog post but hadn’t yet looks
through our codebase for it.