Reputation: 10147
I found information from this thread and am starting to wonder if the information provided there is relevant to the cause of the issue I'm facing.
The QMap
takes the following template arguments:
QMap< QString, int >
My main issue is that I'm initializing a cube class, and within that class contains various calls which are supposed to do very specific things.
One in particular revolves around setting up the class' QMap
members.
Observe the following:
mGeometry = new Geometry;
mGeometry->Init();
mCamera = QVector3D( 10.0, 10.0, 10.0 );
mCubeage.insert( "cubes", 0 );
Debug Output from mCubeage.insert( "cubes", 0 );
// ASCII compatibility
1) (uh oh)
#ifndef QT_NO_CAST_FROM_ASCII
inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const char *ch) : d(fromAscii_helper(ch))
{}
2)
template <class Key, class T>
Q_INLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::insert(const Key &akey,
const T &avalue)
{
detach(); //the called function
QMapData::Node *update[QMapData::LastLevel + 1];
QMapData::Node *node = mutableFindNode(update, akey);
if (node == e) {
node = node_create(d, update, akey, avalue);
} else {
concrete(node)->value = avalue;
}
return iterator(node);
}
3)
bool operator==(const QMap<Key, T> &other) const;
inline bool operator!=(const QMap<Key, T> &other) const { return !(*this == other); }
inline int size() const { return d->size; }
inline bool isEmpty() const { return d->size == 0; }
inline void detach() { if (d->ref != 1) detach_helper(); } //the called function/if statement
inline bool isDetached() const { return d->ref == 1; }
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
inline bool isSharedWith(const QMap<Key, T> &other) const { return d == other.d; }
inline void setInsertInOrder(bool ordered) { d->insertInOrder = ordered; }
inline bool operator!=(int value) const
{
return _q_value != value;
}
4)
inline bool operator!=(int value) const
{
return _q_value != value;
}
And...that's where it stops - BOOM, segmentation fault. According to some of the Qt forums out there - in the realm of Internet - it is unwise to declare pointers to QMap
s, which I originally thought of doing mainly because of the fact that one possible reason for this happening could be due to the fact that the QMap
may not have been initialized properly. Yet, the fact that it's a class member which has a default constructor I believe contradicts this.
Question
According to the above, why is this happening? What can be done about it?
Thoughts
Before someone mentions the fact that I'm passing a const char*
to a QString
parameter, I should note that I have already tried declaring a QString and passing it that as an argument. I should also probably note that I'm running this from Ubuntu 11.10, in Qt Creator.
Upvotes: 1
Views: 2690
Reputation: 64283
What can be done about it?
There is only one thing : run your program under valgrind, and fix all problems you find.
Why is it happening?!? Who knows? You didn't provide enough information. Maybe stack smash, maybe you overwrote passed the end of some arrays, etc.
Upvotes: 2