I'm developing a little app in C++ using the MVP pattern, but I'm not able to connect the controller with the view and vice versa to exchange signals and slots.
This is the overview of my application:

In particular, from the menu bar, when I choose a QAction, a window opens with fields to fill in. Once you have filled in the fields of the window and pressed the "Add service" button, I should be able to send the signal to the controller (by means of a triggered() signal) which will have to notify the model (to add a new service in the container). This model, as soon as it has added the service in the container, will have to emit a signal (serviceAdded() that the container will have to "capture" and then do other things (update the view with the services present in the container and close the open window to add service). I wanted to understand how to connect the controller and the view when: the QPushButton is pressed to add the service and how to close the window, after receiving the signal from the model.
I set up the controller like this:
class Controller : public QObject{
Q_OBJECT
private:
Model * model;
MainView * view;
public:
explicit Controller(Model * m, MainView * mv);
While my main view is set up like this:
class Controller;
class MainView : public QWidget {
Q_OBJECT
private:
QHBoxLayout* mainLayout;
QTableWidget* table;
QMenuBar* menu;
Controller * controller;
public:
explicit MainView(QWidget *parent=nullptr);
When QAction (QAction * artGenerico) is pressed, this happens:
connect(artGenerico, SIGNAL(triggered()), this, SLOT(articoloGenericoWindow()));
This code is part of the view.
And “articoloGenericoWindow()” is:
void MainView::articoloGenericoWindow(){
ArticoloGenericoView * w = new ArticoloGenericoView();
w->show();
connect(controller, SIGNAL(closeWindow()), this, SLOT(close()));
}
Also this code is part of the view.
The problem is that the controller is not connected to anything, even the compiler tells me: “QObject:: connect: Cannot connect (nullptr):: closeWindow () to MainView:: close ()”. In fact, the window does not close when I click on the button.
How can I connect the controller with the view?
I hope I have expressed myself correctly.
