From: Diane Trout Date: Thu, 7 Dec 2006 00:23:14 +0000 (+0000) Subject: Allocating objects in the constructor causes problems X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=68d90f0eac60f549578f2e5fceeff509cfc200ef Allocating objects in the constructor causes problems What do you know, being lazy and initializing Qt GUI objects in the constructor cause problems. (AKA a segfault when running as a test case). This patch allocates the various GUI objects in an actual function (which is so the different contstructors can use the same initialization code. It looks like another coding standard to remember. --- diff --git a/qui/seqbrowser/SequenceDescription.cpp b/qui/seqbrowser/SequenceDescription.cpp index 4b2f66b..5c2a527 100644 --- a/qui/seqbrowser/SequenceDescription.cpp +++ b/qui/seqbrowser/SequenceDescription.cpp @@ -4,14 +4,14 @@ using namespace std; SequenceDescription::SequenceDescription(QWidget *parent) : QFrame(parent), - layout(new QVBoxLayout), - name_label(new QLineEdit), - position_label(new QLabel), - length_label(new QLabel), + layout(0), + name_label(0), + position_label(0), + length_label(0), pos(-1) // set pos to an invalid value so the setPos function will call // setText { - createWidget(); + setupWidgets(); } SequenceDescription::SequenceDescription( @@ -19,11 +19,17 @@ SequenceDescription::SequenceDescription( QWidget *parent ) : QFrame(parent) { + setupWidgets(); setGlSequence(glseq); } -void SequenceDescription::createWidget() +void SequenceDescription::setupWidgets() { + layout = new QVBoxLayout; + name_label = new QLineEdit; + position_label = new QLabel; + length_label = new QLabel; + setFrameStyle(QFrame::Panel | QFrame::Sunken); setLineWidth(1); diff --git a/qui/seqbrowser/SequenceDescription.hpp b/qui/seqbrowser/SequenceDescription.hpp index 1a80779..61b3d2f 100644 --- a/qui/seqbrowser/SequenceDescription.hpp +++ b/qui/seqbrowser/SequenceDescription.hpp @@ -48,7 +48,8 @@ private: boost::shared_ptr glsequence_; int pos; - void createWidget(); + //! finish initializing GUI widgets + void setupWidgets(); //! format the length and set the QLabel void setLength(int length); };