| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 3 | |
Hello everybody,
I have a problem with the the QMap class, following errors are coming:
Program received signal SIGSEGV, Segmentation fault.
0x000000000041da14 in QMap<int, TagItem*>::isEmpty (this=0x706f746b73654483)
at /usr/include/qt4/QtCore/qmap.h:166
166 inline bool isEmpty() const { return d->size == 0; }
I know that at the point when isEmpty is called, the QMap is untouched by the
program. Therefore it should return true but it just crashes. And I am not
sure why.
Here the necessary code (reduced to the relevant parts):
void RDLDMap::addTagItem (int tagId, QColor color)
{
if (tags.isEmpty() || tags.contains(tagId))
return ;
...
}
class TagItem : public QObject, public QGraphicsEllipseItem
{
Q_OBJECT
public:
TagItem ();
void setTagId (int id);
int getTagId ();
signals:
void mouseEnterTag (int tagId, int x, int y);
void mouseLeaveTag ();
void mouseMoveOverTag (int tagId, int x, int y);
protected:
void hoverEnterEvent (QGraphicsSceneHoverEvent * event);
void hoverLeaveEvent (QGraphicsSceneHoverEvent * event);
void hoverMoveEvent (QGraphicsSceneHoverEvent * event);
private:
int tagId;
};
class RDLDMap : public QGraphicsScene
{
Q_OBJECT
...
public slots:
void addTagItem (int tagId, QColor color);
...
private:
QMap <int, TagItem *> tags;
...
};
I tried it also without the isEmpty and only the contains, resulting into:
if (tags.contains(tagId))
Program received signal SIGSEGV, Segmentation fault.
0x000000000041d606 in QMap<int, TagItem*>::findNode (this=0x706f746b73654483,
akey=@0x7fffafdac2c4) at /usr/include/qt4/QtCore/qmap.h:424
424 QMapData::Node *cur = e;
and i tried the direct access:
if (tags[tagId])
Program received signal SIGSEGV, Segmentation fault.
0x000000000041da58 in QMap<int, TagItem*>::detach (this=0x706f746b73654483)
at /usr/include/qt4/QtCore/qmap.h:168
168 inline void detach() { if (d->ref != 1) detach_helper(); }
Thank you for your help in advance.
--
[ signature omitted ]
Your RDLDMap is probably null or previously deleted.
> -----Original Message-----
> From: SirTwist@xxxxxx [mailto:SirTwist@xxxxxx]
> Sent: Saturday, March 15, 2008 7:36 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Segmentation faults caused by QMap
>
> Hello everybody,
>
> I have a problem with the the QMap class, following errors are coming:
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x000000000041da14 in QMap<int, TagItem*>::isEmpty
> (this=0x706f746b73654483)
> at /usr/include/qt4/QtCore/qmap.h:166
> 166 inline bool isEmpty() const { return d->size == 0; }
>
> I know that at the point when isEmpty is called, the QMap is untouched
> by the
> program. Therefore it should return true but it just crashes. And I am
> not
> sure why.
>
> Here the necessary code (reduced to the relevant parts):
>
> void RDLDMap::addTagItem (int tagId, QColor color)
> {
> if (tags.isEmpty() || tags.contains(tagId))
> return ;
> ...
> }
>
> class TagItem : public QObject, public QGraphicsEllipseItem
> {
> Q_OBJECT
> public:
> TagItem ();
> void setTagId (int id);
> int getTagId ();
>
> signals:
> void mouseEnterTag (int tagId, int x, int y);
> void mouseLeaveTag ();
> void mouseMoveOverTag (int tagId, int x, int y);
>
> protected:
> void hoverEnterEvent (QGraphicsSceneHoverEvent * event);
> void hoverLeaveEvent (QGraphicsSceneHoverEvent * event);
> void hoverMoveEvent (QGraphicsSceneHoverEvent * event);
>
> private:
> int tagId;
> };
>
> class RDLDMap : public QGraphicsScene
> {
> Q_OBJECT
> ...
> public slots:
> void addTagItem (int tagId, QColor color);
> ...
> private:
> QMap <int, TagItem *> tags;
> ...
> };
>
> I tried it also without the isEmpty and only the contains, resulting
> into:
> if (tags.contains(tagId))
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x000000000041d606 in QMap<int, TagItem*>::findNode
> (this=0x706f746b73654483,
> akey=@0x7fffafdac2c4) at /usr/include/qt4/QtCore/qmap.h:424
> 424 QMapData::Node *cur = e;
>
> and i tried the direct access:
> if (tags[tagId])
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x000000000041da58 in QMap<int, TagItem*>::detach
> (this=0x706f746b73654483)
> at /usr/include/qt4/QtCore/qmap.h:168
> 168 inline void detach() { if (d->ref != 1) detach_helper(); }
>
> Thank you for your help in advance.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
N§²æìr¸zÇu©[hªØµêÞÚÞçÚè[^r(éì®&Þ{azËç-¢»ayºÈ¬µªÜ+Þjwbú+«b¢xm¶ÿ+-²Úè[^r(ú{^ë-
Scott Aron Bloom wrote: >Your RDLDMap is probably null or previously deleted. I'd go further and say the object that contains RDLDMap has already been deleted. Simon did not show us the code that calls RDLDMap::addTagItem, which is where the problem is. >> Program received signal SIGSEGV, Segmentation fault. >> 0x000000000041da14 in QMap<int, TagItem*>::isEmpty >> (this=0x706f746b73654483) The "this" pointer above is obviously garbage. You don't have to understand the platform in question (looks like AMD64 Linux) to know it. All you have to do is see that it ends in "3", which is not a multiple of 4. With very, very few exceptions (and I can't think of any right now), Qt classes contain at least one pointer, which means they get the alignment requirement of pointers in that platform. Which is to say that the entire class must be aligned on 32- or 64-bit boundaries. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Thank you both next time i go to bed first and ask the question later. Thiago Macieira wrote: > Scott Aron Bloom wrote: > >Your RDLDMap is probably null or previously deleted. > > I'd go further and say the object that contains RDLDMap has already been > deleted. Simon did not show us the code that calls RDLDMap::addTagItem, > which is where the problem is. > I accidently created a new object of RDLDMap with the same name in the constructor instead of using the private of the class > >> Program received signal SIGSEGV, Segmentation fault. > >> 0x000000000041da14 in QMap<int, TagItem*>::isEmpty > >> (this=0x706f746b73654483) > > The "this" pointer above is obviously garbage. You don't have to > understand the platform in question (looks like AMD64 Linux) to know it. > All you have to do is see that it ends in "3", which is not a multiple of > 4. I never heard of the ending in 3 instead of a multiple of 4, what is this for? > With very, very few exceptions (and I can't think of any right now), Qt > classes contain at least one pointer, which means they get the alignment > requirement of pointers in that platform. Which is to say that the entire > class must be aligned on 32- or 64-bit boundaries. I do not understand what this has to do with my problem. -- [ signature omitted ]
> Thank you both > next time i go to bed first and ask the question later. > > Thiago Macieira wrote: > > Scott Aron Bloom wrote: > > >Your RDLDMap is probably null or previously deleted. > > > > I'd go further and say the object that contains RDLDMap has already > been > > deleted. Simon did not show us the code that calls > RDLDMap::addTagItem, > > which is where the problem is. > > > > I accidently created a new object of RDLDMap with the same name in the > constructor instead of using the private of the class > > > >> Program received signal SIGSEGV, Segmentation fault. > > >> 0x000000000041da14 in QMap<int, TagItem*>::isEmpty > > >> (this=0x706f746b73654483) > > > > The "this" pointer above is obviously garbage. You don't have to > > understand the platform in question (looks like AMD64 Linux) to know > it. > > All you have to do is see that it ends in "3", which is not a > multiple of > > 4. > I never heard of the ending in 3 instead of a multiple of 4, what is > this for? > > > With very, very few exceptions (and I can't think of any right now), > Qt > > classes contain at least one pointer, which means they get the > alignment > > requirement of pointers in that platform. Which is to say that the > entire > > class must be aligned on 32- or 64-bit boundaries. > > I do not understand what this has to do with my problem. What he was saying, is if you analize the value of this, (0x706.....4483) is that the memory address was clearly corrupt since pointers must be aligned on a memory boundry... Allowing you to see that it was not a QT issue, but rather a memory management issue on your part.... That said, Im glad you are on the right track to find your problem Scott -- [ signature omitted ]
Simon Schäfer wrote: > I never heard of the ending in 3 instead of a multiple of 4, what is this for? > >> With very, very few exceptions (and I can't think of any right now), Qt >> classes contain at least one pointer, which means they get the alignment >> requirement of pointers in that platform. Which is to say that the entire >> class must be aligned on 32- or 64-bit boundaries. > > I do not understand what this has to do with my problem. Your pointer address was not aligned on a 4-byte boundary. Most processors require that memory accesses be made to addresses aligned to some "natural" multiple of a byte, usually 4, else they execute an exception, which your program eventually displays as a core dump. So if you ever see a pointer ending in anything other than a multiple of 4, there's a good chance that it is invalid, and that something bad will happen if you try to dereference it. -- [ signature omitted ]