I'm new to C++ and I'm trying to find the proper way to initialize this class.
Here is the code:
void NewDialog::createNew()
{
InkSpot *ink;
ink = new InkSpot(this);
InkPuppet *puppet;
puppet->ui->canvas->addWidget(ink->widget);
close();
}
Now, for InkSpot *ink;
& ink = new InkSpot(this);
it works fine because I actually DO need a new InkSpot created.
But I do not need a new InkPuppet *puppet
created, I simply need to refer to it's UI. Using the above code puppet->ui->canvas->addWidget(ink->widget);
causes the program to crash because it is not being initialized.
The whole issue here is, that to initialize a new class I know how to do it, but initializing a pre-existing class I'm not sure how to refer to it.
newdialog.h
#ifndef NEWDIALOG_H
#define NEWDIALOG_H
#include "inkspot.h"
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include <QDialog>
namespace Ui {
class NewDialog;
}
class NewDialog : public QDialog
{
Q_OBJECT
public:
explicit NewDialog(QWidget *parent = 0);
~NewDialog();
InkPuppet *pointerToPuppet;
private:
Ui::NewDialog *ui;
private slots:
void createNew(InkPuppet *existingPuppet);
};
#endif // NEWDIALOG_H
inkpuppet.h
#ifndef INKPUPPET_H
#define INKPUPPET_H
#include "inkspot.h"
#include "ui_inkpuppet.h"
#include <QMainWindow>
#include <QWidget>
namespace Ui {
class InkPuppet;
}
class InkPuppet : public QMainWindow
{
Q_OBJECT
public:
explicit InkPuppet(QWidget *parent = 0);
~InkPuppet();
Ui::InkPuppet *ui;
private slots:
void setMinimum(int value);
void setMaximum(int value);
void actionNew();
void actionAbout();
void testButton();
};
#endif // INKPUPPET_H