Re: No such slot. Connection done in base class. Using model/view framework.
I am using a model/view framework and have the following classes: customer_model, base_model, customer_view, and main_window. Also, customer_model inherits from base_model. I have placed a connection statement in base_model to throw a signal that is caught by the customer_view slot.
I get the error: QObject::connect: No such slot CustomerView::SlotLogErrorMessage(QString title, QString message, bool message_box) in base_model.cpp:34
QObject::connect: (receiver name: 'CustomerView').
The slot is there, so what is the problem?
Here is the code:
MainWindow.h
Code:
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
...
private:
CustomerView* m_customer_view;
};
MainWindow.cpp
Code:
{
setupUi(this);
m_customer_view = new CustomerView(this);
...
}
customer_view.h
Code:
class CustomerView
: public QWidget, Ui
::CustomerView{
Q_OBJECT
public:
explicit CustomerView
(QWidget *parent
= 0);
...
void SlotLogErrorMessage
(QString title,
QString message,
bool message_box
);
private:
CustomerModel* m_customer_model;
...
};
customer_view.cpp
Code:
CustomerView
::CustomerView(QWidget *parent
) : QWidget(parent
), Ui
::CustomerView(){
setupUi(this);
m_customer_model = new CustomerModel(this);
...
}
void CustomerView
::SlotLogErrorMessage(QString title,
QString message,
bool message_box
) {
if(message_box)
{
}
}
customer_model.h
Code:
class CustomerModel : public BaseModel
{
Q_OBJECT
public:
explicit CustomerModel
(QObject *parent
= 0);
...
};
base_model.h
Code:
{
Q_OBJECT
public:
explicit BaseModel
(QObject* parent
= 0);
signals:
void SignalLogErrorMessage
(QString title,
QString message,
bool message_box
);
...
};
base_model.cpp
Code:
{
connect(this,
SIGNAL(SignalLogErrorMessage
(QString,
QString,
bool)), parent,
SLOT(SlotLogErrorMessage
(QString title,
QString message,
bool message_box
)));
...
}
What is wrong with the connect statement? Thanks for looking at this problem.
The problem was in identifying the variable names in the connect statement. Should have just used the data type.
The problem was in identifying the variable names in the connect statement. Should have just used the data type.
Re: No such slot. Connection done in base class. Using model/view framework.
Quote:
The problem was in identifying the variable names in the connect statement.
Maybe. It was probably also due to not declaring SlotLogErrorMessage() as a slot in the CustomerView class definition in customer_view.h (i.e. not using the "slots" keyword), although in Qt5 any method, even a lambda, can be used as a slot if the signature matches the signal signature or some part of it.
The SIGNAL() and SLOT() macros in the version of the connect() statement you used require the slots keyword because they rely on the moc metacompiler to parse the slot method declarations and produce the code needed to identify the slot methods so they can be verified and connected at run time (as opposed to compile time verification for lambdas and ordinary functions not declared with the slots keyword).