I also like foreach because its easy to use, avoids unnecessary copying and very readable and the performance is ok:
Qt Code:
foreach(const QUrl& url, event->mimeData()->urls()) { //work }To copy to clipboard, switch view to plain text mode
I also like foreach because its easy to use, avoids unnecessary copying and very readable and the performance is ok:
Qt Code:
foreach(const QUrl& url, event->mimeData()->urls()) { //work }To copy to clipboard, switch view to plain text mode
As the documentation says.Qt automatically takes a copy of the container
So make me correct, but isn't foreach loop something useful when iterating through the container holding pointers not entire objects, because in other way we use 2 times original_container_size amount of memory ?
My schedule makes my cry
My works makes my laugh
My life makes... oh...no....
It depends on the container. All Qt containers are implcitly shared so only a shallow copy of the container is made, the real data is not copied. If you create your own container (or use some 3rd party code) that doesn't share data between its copies then foreach will cause an immediate overhead in both memory and time because the container will have to be copied.
Bookmarks