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
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
...
private:
CustomerView* m_customer_view;
};
class MainWindow : public QMainWindow, Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
...
private:
CustomerView* m_customer_view;
};
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
{
setupUi(this);
m_customer_view = new CustomerView(this);
...
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), Ui::MainWindow()
{
setupUi(this);
m_customer_view = new CustomerView(this);
...
}
To copy to clipboard, switch view to plain text mode
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;
...
};
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;
...
};
To copy to clipboard, switch view to plain text mode
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)
{
}
}
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);
}
}
To copy to clipboard, switch view to plain text mode
customer_model.h
class CustomerModel : public BaseModel
{
Q_OBJECT
public:
explicit CustomerModel
(QObject *parent
= 0);
...
};
class CustomerModel : public BaseModel
{
Q_OBJECT
public:
explicit CustomerModel(QObject *parent = 0);
...
};
To copy to clipboard, switch view to plain text mode
base_model.h
{
Q_OBJECT
public:
explicit BaseModel
(QObject* parent
= 0);
signals:
void SignalLogErrorMessage
(QString title,
QString message,
bool message_box
);
...
};
class BaseModel : public QObject
{
Q_OBJECT
public:
explicit BaseModel(QObject* parent = 0);
signals:
void SignalLogErrorMessage(QString title, QString message, bool message_box);
...
};
To copy to clipboard, switch view to plain text mode
base_model.cpp
{
connect(this,
SIGNAL(SignalLogErrorMessage
(QString,
QString,
bool)), parent,
SLOT(SlotLogErrorMessage
(QString title,
QString message,
bool message_box
)));
...
}
BaseModel::BaseModel(QObject *parent) : QObject(parent)
{
connect(this, SIGNAL(SignalLogErrorMessage(QString,QString,bool)), parent, SLOT(SlotLogErrorMessage(QString title, QString message, bool message_box)));
...
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks