Of course, sorry, my bad, I'm just used to C++11 style "for" loops:
for (FileEntry & itmFile : fileList){
//...
}
for (FileEntry & itmFile : fileList){
//...
}
To copy to clipboard, switch view to plain text mode
I forgot the fact that Qt "foreach" makes a copy of the container before entering the loop (but it is cheap thanks to implicit sharing).
Above "for" loop will work as expected.
In order to use it you need to have
1) a compiler that supports c++11 features
2) if not enabled by default, you need to add this to the <project>.pro file:
// .pro
CONFIG += c++11
// .pro
CONFIG += c++11
To copy to clipboard, switch view to plain text mode
Here is a small example:
#include <QList>
#include <QDebug>
struct data_t{
int value;
data_t(int a=0) : value(a){}
};
QDebug& operator<< (QDebug& stream, const data_t& d){
stream << d.value;
return stream;
}
int main(){
QList<data_t> list;
list << data_t(1) << data_t(2) << data_t(3);
qDebug() << list;
for (data_t& d : list){
d.value += 1;
}
qDebug() << list;
return 0;
}
// should output:
// 1, 2, 3)
//(2, 3, 4)
#include <QList>
#include <QDebug>
struct data_t{
int value;
data_t(int a=0) : value(a){}
};
QDebug& operator<< (QDebug& stream, const data_t& d){
stream << d.value;
return stream;
}
int main(){
QList<data_t> list;
list << data_t(1) << data_t(2) << data_t(3);
qDebug() << list;
for (data_t& d : list){
d.value += 1;
}
qDebug() << list;
return 0;
}
// should output:
// 1, 2, 3)
//(2, 3, 4)
To copy to clipboard, switch view to plain text mode
Sorry for the confusion.
Bookmarks