This program is supposed to create the object mBulbPrimary of the class pointCloudBool in the main window and perform calculations which change the content of that object. When clicking the actionSave_Mandelbulb widget a new window DialogSaveMB appears and the user can enter a filepath and click the pushButton_save button. This is supposed to call the mBulbPrimary.savePrimary(filePath) function of the original object.
However in dialogsavemb.cpp the mBulbPrimary object is not recogized and I don't understand why. The object is public and mainwindow.h is included in dialogsavemb.cpp so why can't it access the object or its methods/functions?
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "dialogsavemb.h"
#include "pointcloudbool.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class DialogSaveMB;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
DialogSaveMB dialogSaveMB; //Dialog window
pointCloudBool mBulbPrimary; //public mBulbPrimary object
private:
Ui::MainWindow *ui;
private slots:
//unrelated functions...
void openSaveMBulbWindow();
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//unrelated connections...
connect(ui->actionSave_Mandelbulb, SIGNAL(triggered(bool)),
this, SLOT(openSaveMBulbWindow()));
}
MainWindow::~MainWindow()
{
delete ui;
}
//Implementation:
//unrelated functions...
void MainWindow::openSaveMBulbWindow(){
dialogSaveMB.show();
}
dialogsavemb.h:
#ifndef DIALOGSAVEMB_H
#define DIALOGSAVEMB_H
#include <QDialog>
namespace Ui {
class DialogSaveMB;
}
class DialogSaveMB : public QDialog
{
Q_OBJECT
public:
explicit DialogSaveMB(QWidget *parent = nullptr);
~DialogSaveMB();
private:
Ui::DialogSaveMB *ui;
private slots:
void saveMBulb(std::string filePath);
};
#endif // DIALOGSAVEMB_H
dialogsavemb.cpp:
#include "dialogsavemb.h"
#include "ui_dialogsavemb.h"
#include "mainwindow.h"
DialogSaveMB::DialogSaveMB(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSaveMB)
{
ui->setupUi(this);
ui->radioButton_txt->setChecked(true);
//Get filepath from a lineEdit widget of the dialog:
std::string filePath = ui->lineEdit_filePath->text().toUtf8().constData();
//unrelated connections...
connect(ui->pushButton_save, SIGNAL(clicked(bool)),
this, SLOT(saveMBulb(filePath)));
}
DialogSaveMB::~DialogSaveMB()
{
delete ui;
}
void DialogSaveMB::saveMBulb(std::string filePath){
mBulbPrimary.savePrimary(filePath);
//The above line needs to access the 'mBulbPrimary' object in the MainWindow class
//but it can't.
}
saveMBulb. Then in MainWindow, connect this signal to a slot which handles the file name.connect(dialogSaveMB.ui->pushButton_save, SIGNAL(clicked(bool)), this, SLOT(saveMBulb(filePath)));