Now I make a function within CochlearImplantExperiment_amt. This function is a public slot, and is called void doimplantscomeinellipses(). All this function does is make drawstuff->drawEllipse(100,100,250,100) whenever a button is clicked. But for some reason it always generates a runtime error. I cut and paste the drawEllipse line into the constructor, and sure enough the ellipse is painted.
As far as I know, anything that's declared/used in the class should be able to access one another. Why does it then give a runtime error? Probably because that isn't the case. But I would really really like to avoid making a QPixmap, making a QLabel to display said pixmap, and making a QPainter all within each function that is meant to simply draw a particular shape on the screen.
What's wrong here? I've included some snippets of code, first up is the header file:
Code: Select all
public slots:
void nameInputChanged( const QString & );
void distanceModeChosen(const QString & string);
void operationModeChosen(const QString & string);
void modeClicked(int id);
void startStopClicked();
void doimplantscomeinellipses();
protected:
QWidget* _guiTab;
QLabel* _nameLabel;
QLabel* _testLabel;
//DisplayWidget_amt* _displayWidget;
CameraInterface_amt* _cam;
QLineEdit* _nameInput;
QComboBox* _frequencyBox;
QPixmap *pixmap;
QLabel *pixmaplabel;
QPainter *drawstuff;
QPushButton* _startStopButton;
QPushButton *ellipse;
QPointArray splineone;
QString* _subjectName;
Code: Select all
void CochlearImplantExperiment_amt::doimplantscomeinellipses()
{
drawstuff->drawEllipse(100,100,200,150);
}
In the constructor:
Code: Select all
QPushButton *ellipse = new QPushButton("&Ellipse", modeFrame);
ellipse->setGeometry(10,160,100,40);
connect(ellipse,SIGNAL(clicked()),this,SLOT(doimplantscomeinellipses()));
QLabel *pixmaplabel = new QLabel(testFrame);
pixmap = new QPixmap(650,600);
pixmaplabel->setPixmap(*pixmap);
pixmaplabel->setAutoResize(TRUE);
QPainter *drawstuff = new QPainter(pixmap);
QPointArray splineone(4);
splineone[0]=QPoint(50,50);
splineone[1]=QPoint(150,0);
splineone[2]=QPoint(150,150);
splineone[3]=QPoint(400,200);
drawstuff->setPen(Qt::red);
drawstuff->drawRect(10,10,200,100);
drawstuff->drawCubicBezier(splineone);
drawstuff->drawRoundRect(200,180,400,320);
_nameInput = new QLineEdit(modeFrame);
_nameInput->setGeometry(10,50,280,45);
connect(_nameInput,SIGNAL(textChanged ( const QString & )),this,SLOT(nameInputChanged( const QString & )));