I have a really "funny" (not really) problem involving QList.
I have a class File that, as a member, has a QList<Part>:
class File {
public:
QList<Part> parts;
}
class File {
public:
QList<Part> parts;
}
To copy to clipboard, switch view to plain text mode
A file object is passed to a worker thread for processing:
public:
Decoder(File f) { file = f; }
void run();
private:
File file;
}
class Decoder : public QThread {
public:
Decoder(File f) { file = f; }
void run();
private:
File file;
}
To copy to clipboard, switch view to plain text mode
In the run() function, I construct the file from the parts that are associated with that file:
void Decoder::run() {
QList<Part>::iterator partIter;
for (partIter = file.parts.begin(); partIter != file.parts.end(); partIter++) {
// do stuff with *partIter
}
}
void Decoder::run() {
QList<Part>::iterator partIter;
for (partIter = file.parts.begin(); partIter != file.parts.end(); partIter++) {
// do stuff with *partIter
}
}
To copy to clipboard, switch view to plain text mode
(simplified representation)
This works perfectly fine if parts holds more than 1 part. If the number of parts is 1, the loop is done twice and of course, I get a segfault in the second iteration.
For completeness I should mention that file has been passed around by signal/slot connections, e.g. someSlot(const File f).
I have no clue why this could be happening. Any ideas?
Bookmarks