EVARATE
12th April 2020, 17:42
In my MainWindow there is a button that opens the MbulbWindow. There one can change some parameters and click a Generate button which calls the generateMBulb() function which does some calculation and in the end creates an object named entity of the class internalEntity.
Now I want to "send" this entity to the MainWindow where it will be saved for later use. But how do I do that? My idea was to create the transferEntity(internalEntity& entity) signal and connect it to the addEntity(internalEntity& entity) function of the MainWindow but Qt always gives an error message similar to the following:
QObject::connect: No such signal MbulbWindow::MBulbWindow::transferEntity() in ../MandelbulbUI_rewrite/mainwindow.cpp:15
QObject::connect: (sender name: 'MbulbWindow')
QObject::connect: (receiver name: 'MainWindow')
Here are my files:
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWindow>
#include <QAction>
#include "mbulbwindow.h"
#include "internalentityhandler.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
internalEntityHandler entityHandler; //Saves and manages entities
MbulbWindow *mBulbWindow = new MbulbWindow;
private slots:
//...
//Generate
void showMBGenerator();
//internal entity management
void addEntity(internalEntity& entity);
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//...
//Connections
internalEntity entity;
connect(mBulbWindow, SIGNAL(MBulbWindow::transferEntity()), this, SLOT(addEntity()));
//This is where I would make the connection
}
MainWindow::~MainWindow()
{
delete ui;
}
//...
//Generate
void MainWindow::showMBGenerator(){
mBulbWindow->show();
}
//internal entity management
void MainWindow::addEntity(internalEntity& entity){
//Entity in memory:
entityHandler.addEntity(entity);
//...
}
mbulbwindow.h:
#ifndef MBULBWINDOW_H
#define MBULBWINDOW_H
#include <QDialog>
#include <vector>
#include "boolcloud.h"
#include "internalentityhandler.h"
namespace Ui {
class MbulbWindow;
}
class MbulbWindow : public QDialog
{
Q_OBJECT
public:
explicit MbulbWindow(QWidget *parent = nullptr);
~MbulbWindow();
private:
Ui::MbulbWindow *ui;
private slots:
void generateMBulb();
signals:
void transferEntity(internalEntity& entity);
};
#endif // MBULBWINDOW_H
mbulbwindow.cpp:
#include "mbulbwindow.h"
#include "ui_mbulbwindow.h"
MbulbWindow::MbulbWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::MbulbWindow)
{
ui->setupUi(this);
//Connections
connect(ui->ButtonGenerate, SIGNAL(clicked()), this, SLOT(generateMBulb()));
}
MbulbWindow::~MbulbWindow()
{
delete ui;
}
void MbulbWindow::generateMBulb(){
//Calculation of "mBulb" object...
//Create entity
internalEntity entity(mBulb, "Mandelbulb");
emit transferEntity(entity);
//This entity needs to be transferred to the MainWindow
this->close();
}
Now I want to "send" this entity to the MainWindow where it will be saved for later use. But how do I do that? My idea was to create the transferEntity(internalEntity& entity) signal and connect it to the addEntity(internalEntity& entity) function of the MainWindow but Qt always gives an error message similar to the following:
QObject::connect: No such signal MbulbWindow::MBulbWindow::transferEntity() in ../MandelbulbUI_rewrite/mainwindow.cpp:15
QObject::connect: (sender name: 'MbulbWindow')
QObject::connect: (receiver name: 'MainWindow')
Here are my files:
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWindow>
#include <QAction>
#include "mbulbwindow.h"
#include "internalentityhandler.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
internalEntityHandler entityHandler; //Saves and manages entities
MbulbWindow *mBulbWindow = new MbulbWindow;
private slots:
//...
//Generate
void showMBGenerator();
//internal entity management
void addEntity(internalEntity& entity);
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//...
//Connections
internalEntity entity;
connect(mBulbWindow, SIGNAL(MBulbWindow::transferEntity()), this, SLOT(addEntity()));
//This is where I would make the connection
}
MainWindow::~MainWindow()
{
delete ui;
}
//...
//Generate
void MainWindow::showMBGenerator(){
mBulbWindow->show();
}
//internal entity management
void MainWindow::addEntity(internalEntity& entity){
//Entity in memory:
entityHandler.addEntity(entity);
//...
}
mbulbwindow.h:
#ifndef MBULBWINDOW_H
#define MBULBWINDOW_H
#include <QDialog>
#include <vector>
#include "boolcloud.h"
#include "internalentityhandler.h"
namespace Ui {
class MbulbWindow;
}
class MbulbWindow : public QDialog
{
Q_OBJECT
public:
explicit MbulbWindow(QWidget *parent = nullptr);
~MbulbWindow();
private:
Ui::MbulbWindow *ui;
private slots:
void generateMBulb();
signals:
void transferEntity(internalEntity& entity);
};
#endif // MBULBWINDOW_H
mbulbwindow.cpp:
#include "mbulbwindow.h"
#include "ui_mbulbwindow.h"
MbulbWindow::MbulbWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::MbulbWindow)
{
ui->setupUi(this);
//Connections
connect(ui->ButtonGenerate, SIGNAL(clicked()), this, SLOT(generateMBulb()));
}
MbulbWindow::~MbulbWindow()
{
delete ui;
}
void MbulbWindow::generateMBulb(){
//Calculation of "mBulb" object...
//Create entity
internalEntity entity(mBulb, "Mandelbulb");
emit transferEntity(entity);
//This entity needs to be transferred to the MainWindow
this->close();
}