Original Post
Hey guys, i'm working with g++, boost and Linux and am trying to get this running:
//conditioneditor.h
class ConditionEditor : public QWidget
{
Q_OBJECT
public:
ConditionEditor();
void setText(QString text);
QString text();
private:
QVBoxLayout *layout;
boost::shared_ptr<int> ptr;
QString m_text;
};
//conditioneditor.cpp
ConditionEditor::ConditionEditor()
: QWidget(),
layout(new QVBoxLayout(this)),
ptr(new int(5)),
m_text("")
{}
Forget about the Qt Stuff. Also the pointer type int is just an example here to make things easier. I get a segfault when executing this code. I get a segfault as long as i'm using a smart pointer as a member variable. It doesn't matter if it isn't initialized, or if it's initialized via MIL (as above) or via assignment. I don't get why I can't use the smart pointer as a member. If I put it into the constructor (which doesn't make sense for what I want), the code compiles and executes. Any ideas? EDIT: uhm, I still forgot another thing I tried. I made the smart pointer static. Then the program didn't crash anymore. Why that? The problem is that I don't want the variable to be static.