[Qt-interest] Pointer issue
Konrad Rosenbaum
konrad at silmor.de
Thu Feb 26 09:27:02 CET 2009
On Wednesday 25 February 2009, Zine eddine Bendjaballah wrote:
> I've a class called "Subject" in my project.
>
> And an other class called SubjectModel;
>
> class SubjectModel: public QAbstractTableModel
> {
> Q_OBJECT
>
> public:
> //Public declarations
> ...
> private:
> QList <Subject*> subjects ;
> };
> My program crashes when it arrive at this instruction:
>
> if (subjects[i]->name == initialSubjectName)
Why not use QList<Subject> instead? According to the code you've shown it
should not be too expensive to copy it (QStrings are implicitly shared and
QColor is really small). This would save you all the headaches of pointer
operation.
Or at the very least declare it as QList<QPointer<Subject> > and check
subjects[i].isNull() before you use the pointer.
Konrad
--
Note: I'm changing my PGP/GPG key soon! New KeyID: 723A6200
Fingerprint: B37C FA75 8C4C 6537 7954 CBC0 CB15 C991 723A 6200
Keyserver: wwwkeys.eu.pgp.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090226/8cf93a9b/attachment.bin
More information about the Qt-interest-old
mailing list