I have three forms. By pressing the button on the first form, the second appears. By pressing the button on the second form, the third appears. By pressing a button on the third form, information is transmitted to the first form.

There is a problem with the transmission of the signal of the first form. The problem is as follows.

I connect the signal from the third form and the slot from the first.

connect(this, SIGNAL(send_signal_replot_R(DAG) ), this->baseClass, SLOT(replot_matrix_R(DAG) ) ); 

The signal is declared as follows:

 signals: void send_signal_replot_R(DAG graph); 

The slot is declared as follows:

 public slots: void replot_matrix_R(DAG graph); 

A slot is such a function:

 void Main_Window::replot_matrix_R(DAG graph) { this->graph = graph; ui->widget->Graph() = graph; ui->widget->before_paint(); ui->widget->repaint(); return; } 

Call the signal like this:

 emit this->send_signal_replot_R(graph); 

As a result, I get something like this:

 QObject::connect: Cannot connect Calculate::send_signal_replot_R(DAG) to (null)::Main_Window::replot_matrix_R(DAG) 

I do not understand what is (null). This is a bit strange, i.e. Isn't a slot connected to a class? Or what is the bug? I tried to modify the connection with the slot for this, but did not help:

 connect(this, SIGNAL(send_signal_replot_R(DAG) ), this->baseClass, SLOT(Main_Window::replot_matrix_R(DAG) ) ); 

Initialize this->baseClass :

 Calculate::Calculate(int countMatrix, int countVertex, QWidget *baseClass, QWidget *parent) : QDialog(parent), ui(new Ui::Calculate) { ui->setupUi(this); this->countVertex = countVertex; this->countMatrix = countMatrix; this->SetNameLabel(1, countMatrix); InitMatrix(); this->matrixGraph.resize(countVertex, countVertex, 0); this->baseClass = baseClass; this->currentCountMatrix = 0; return; } 

connect is located inside the method:

 void Calculate::on_pushButton_clicked() { ... connect(this, SIGNAL(send_signal_replot_R(DAG) ), this->baseClass, SLOT(Main_Window::replot_matrix_R(DAG) ) ); ... emit this->send_signal_replot_R(graph); ... } 
  • Are you somewhere using Calculate? - Vladimir Martyanov
  • @ VladimirMartyanov, Calculate - the signal is announced to it send_signal_replot_R (DAG) - hedgehogues
  • Did moki reassemble after modification, just in case? .. - LXA
  • Does baseClass have a replot_matrix_R slot? - gil9red
  • @ gil9red baseClass is Main_Window - hedgehogues

1 answer 1

Linking is best done in the constructor, and not on the button click handler.

 this->baseClass = baseClass; connect(this, SIGNAL(send_signal_replot_R(DAG) ), this->baseClass, SLOT(replot_matrix_R(DAG) ) ); 

Check how you create an instance of the Calculate class, and specifically what is being passed as the value of the parameter QWidget * baseClass . The fact is that connect produces "later" binding, i.e. at runtime. If baseClass == null , then you get an error. Other reasons for the error from the presented code, I do not see.

  • Yes, it worked. Thanks you. Did not pass the pointer. And he defaults to 0. - hedgehogues