Home > Back-end >  You can't get a signal Qt slot function
You can't get a signal Qt slot function

Time:12-11

Preface, the need to implement from interface 1 click on the "+" button to jump to 2 interface, then click "cancel"/2 interface "storage" return to the interface 1,
Front is achievable, but click click "cancel"/" storage ", all can send signals, interface 1 slot function receive_save () and couldn't get a signal receive_addid_cancel,,,

Has already done trying: first the connect process is return true, before also has written many similar signal channel not met this kind of question!

Because it involves the interface between 1 and 2 interface of signal channel, I wonder whether slot function have restrictions on the number??

The question has bothered me all day long, to suffocate, quick save the children ~

Interface 1:
Interface 2:

The main. CPP
 # include "widget. H" 
# include "addid. H"
#include
#include
Int main (int arg c, char * argv [])
{
QApplication a (arg c, argv);
Widgets * w=new Widget;
I=new AddId AddId *;
W - & gt; Show ();

QObject: : connect (w, SIGNAL (showAddId ()), I, SLOT (receive_widget_addid ()));
Bool isConnected=QObject: : connect (I, SIGNAL (showLabel ()), w, SLOT (receive_save ()));
QDebug () & lt; QObject: : connect (I, SIGNAL (showWidget ()), w, SLOT (receive_addid_cancel ()));

Return a.e xec ();
}


Interface (1) h (main interface)
 
# # ifndef WIDGET_H
# define WIDGET_H

#include

QT_BEGIN_NAMESPACE
The namespace Ui {class Widget; }
QT_END_NAMESPACE

The class Widget: public QWidget
{
Q_OBJECT

Public:
The parent Widget (QWidget *=nullptr);
~ the Widget ();

Private slots:

Void on_addid_clicked ();

Void receive_save ();

Void receive_addid_cancel ();

Signals:
Void showAddId ();

Private:
Ui: Ui widgets *;
};
# endif//WIDGET_H


Interface CPP (main interface) :
 
# include "widget. H"
# include "ui_widget. H"
#include
#include
#include
#include
#include
#include
#include

Widgets: : widgets (QWidget * parent)
: QWidget (parent)
, the UI (new UI: : Widget)
{
The UI - & gt; SetupUi (this);
}

Widgets: : ~ Widget ()
{
Delete the UI;
}

Void Widget: : on_addid_clicked ()
{
This - & gt; Hide ();
QDebug () & lt; <" Add the interface signal!" ;
Emit showAddId ();
}

Void Widget: : receive_save ()
{
QDebug () & lt; <"Save the reception!" ;
This - & gt; Show ();
}

Void Widget: : receive_addid_cancel ()
{
QDebug () & lt; <"Closing reception!" ;
This - & gt; Show ();
}

Interface (2) h (add id editing interface)
[code]=c # # ifndef ADDID_H
# define ADDID_H

#include

The namespace Ui {
The class AddId;
}

The class AddId: public QWidget
{
Q_OBJECT

Public:
Explicit AddId (QWidget * parent=nullptr);
~ AddId ();

Private slots:

Void receive_widget_addid ();

Void on_save_clicked ();

Void on_cancel_clicked ();

Signals:

Void showWidget ();

Void showLabel ();

Private:
Ui: : Ui AddId *;
};

# endif//ADDID_H


[/code]
Interface 2. CPP (add id edit interface) :
 # include "addid. H" 
# include "ui_addid. H"
#include
#include
#include
#include
# include "widget. H"

AddId: : AddId (QWidget * parent)
: QWidget (parent)
, the UI (new UI: : AddId)
{
The UI - & gt; SetupUi (this);
}

AddId: : ~ AddId ()
{
Delete the UI;
}

Void AddId: : receive_widget_addid ()
{
QDebug () & lt; <"The widget reception!" ;
I=new AddId AddId *;
I - & gt; Show ();
}

Void AddId: : on_save_clicked ()
{
This - & gt; Hide ();
QDebug () & lt; <" Save the signal!" ;
Emit showLabel ();
}

Void AddId: : on_cancel_clicked ()
{
This - & gt; Hide ();
QDebug () & lt; <" Send off signal!" ;
Emit showWidget ();
}

CodePudding user response:

Of the new posts for the first time, baseball to join in, please have a look at ~

CodePudding user response:

CodePudding user response:

Don't want disorderly new, also didn't delete, if it is inherited from Qt class, specify the parent may also will be destroyed, or a memory leak,

CodePudding user response:

First you opened the window, both in the received signal in the add window then new an add window, that you think about yourself, at this time point button belongs to who? QDebug print under this address

CodePudding user response:

refer to the second floor it is a nice nickname response:
is here, to this solved

CodePudding user response:

this is a nice nickname reference 4 floor response:
both of first you open the window, and then in the add window in the received signal and the new one, add window that you want, at this time point button belongs to who? null
  • Related