Results 1 to 2 of 2

Thread: No such slot. Connection done in base class. Using model/view framework.

  1. #1
    Join Date
    May 2019
    Posts
    11
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. class MainWindow : public QMainWindow, Ui::MainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit MainWindow(QWidget *parent = 0);
    7. ...
    8. private:
    9. CustomerView* m_customer_view;
    10. };
    To copy to clipboard, switch view to plain text mode 
    MainWindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), Ui::MainWindow()
    2. {
    3. setupUi(this);
    4. m_customer_view = new CustomerView(this);
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    customer_view.h
    Qt Code:
    1. class CustomerView : public QWidget, Ui::CustomerView
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CustomerView(QWidget *parent = 0);
    6. ...
    7. void SlotLogErrorMessage(QString title, QString message, bool message_box);
    8.  
    9. private:
    10. CustomerModel* m_customer_model;
    11. ...
    12. };
    To copy to clipboard, switch view to plain text mode 
    customer_view.cpp
    Qt Code:
    1. CustomerView::CustomerView(QWidget *parent) : QWidget(parent), Ui::CustomerView()
    2. {
    3. setupUi(this);
    4. m_customer_model = new CustomerModel(this);
    5. ...
    6. }
    7. void CustomerView::SlotLogErrorMessage(QString title, QString message, bool message_box)
    8. {
    9. if(message_box)
    10. {
    11. QMessageBox::warning(this, title, message);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    customer_model.h
    Qt Code:
    1. class CustomerModel : public BaseModel
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CustomerModel(QObject *parent = 0);
    6. ...
    7. };
    To copy to clipboard, switch view to plain text mode 
    base_model.h
    Qt Code:
    1. class BaseModel : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit BaseModel(QObject* parent = 0);
    6. signals:
    7. void SignalLogErrorMessage(QString title, QString message, bool message_box);
    8. ...
    9. };
    To copy to clipboard, switch view to plain text mode 
    base_model.cpp
    Qt Code:
    1. BaseModel::BaseModel(QObject *parent) : QObject(parent)
    2. {
    3. connect(this, SIGNAL(SignalLogErrorMessage(QString,QString,bool)), parent, SLOT(SlotLogErrorMessage(QString title, QString message, bool message_box)));
    4. ...
    5. }
    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.
    Last edited by Debra; 25th October 2019 at 21:23.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No such slot. Connection done in base class. Using model/view framework.

    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).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 5th December 2013, 11:19
  2. Custom ListView. Using the model / view framework.
    By plopes21 in forum Qt Programming
    Replies: 19
    Last Post: 8th May 2012, 09:43
  3. Signal in base class Slot in Subclass
    By csvivek in forum Newbie
    Replies: 7
    Last Post: 30th March 2008, 17:59
  4. QTDesigner base view class
    By dave in forum Newbie
    Replies: 1
    Last Post: 14th November 2006, 22:56
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 08:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.