Debra
25th October 2019, 20:24
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
class MainWindow : public QMainWindow, Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
...
private:
CustomerView* m_customer_view;
};
MainWindow.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), Ui::MainWindow()
{
setupUi(this);
m_customer_view = new CustomerView(this);
...
}
customer_view.h
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
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)
{
QMessageBox::warning(this, title, message);
}
}
customer_model.h
class CustomerModel : public BaseModel
{
Q_OBJECT
public:
explicit CustomerModel(QObject *parent = 0);
...
};
base_model.h
class BaseModel : public QObject
{
Q_OBJECT
public:
explicit BaseModel(QObject* parent = 0);
signals:
void SignalLogErrorMessage(QString title, QString message, bool message_box);
...
};
base_model.cpp
BaseModel::BaseModel(QObject *parent) : QObject(parent)
{
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.
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
class MainWindow : public QMainWindow, Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
...
private:
CustomerView* m_customer_view;
};
MainWindow.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), Ui::MainWindow()
{
setupUi(this);
m_customer_view = new CustomerView(this);
...
}
customer_view.h
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
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)
{
QMessageBox::warning(this, title, message);
}
}
customer_model.h
class CustomerModel : public BaseModel
{
Q_OBJECT
public:
explicit CustomerModel(QObject *parent = 0);
...
};
base_model.h
class BaseModel : public QObject
{
Q_OBJECT
public:
explicit BaseModel(QObject* parent = 0);
signals:
void SignalLogErrorMessage(QString title, QString message, bool message_box);
...
};
base_model.cpp
BaseModel::BaseModel(QObject *parent) : QObject(parent)
{
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.