Results 1 to 5 of 5

Thread: error calling method using connect

  1. #1
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default error calling method using connect

    I am having trouble with the following code can someone explain what i am doing wrong. It is a main window application that has a dialog open up and im trying to create a button that saves the input from the user. but when i press the button it does gives the follwoing error

    Qt Code:
    1. Object::connect: No such slot QDialog::SaveSettings() in serverDialog.cpp:6
    2. Object::connect: (sender name: 'pushButton_Save')
    3. Object::connect: (receiver name: 'Dialog')
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef SERVERDIALOG_H
    2. #define SERVERDIALOG_H
    3.  
    4. #include "ui_serverDialog.h"
    5.  
    6. class ServerDialog: public QDialog, public Ui::Dialog
    7. {
    8. public:
    9. ServerDialog();
    10. protected slots:
    11. void SaveSettings();
    12.  
    13. };
    14.  
    15. #endif // SERVERDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "serverDialog.h"
    2.  
    3. ServerDialog::ServerDialog()
    4. {
    5. setupUi(this);
    6. connect(pushButton_Save, SIGNAL(clicked()), this, SLOT(SaveSettings()));
    7. connect(pushButton_Quit, SIGNAL(clicked()), this, SLOT(close()));
    8. }
    9.  
    10. void ServerDialog::SaveSettings()
    11. {
    12.  
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    This was created using Qtcreator.
    if i change the slot to close() it works perfectly. how would i get the method SaveSettings to run.

    many thanks

    jeff

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error calling method using connect

    Try adding the line "Q_OBJECT" before "public:" so moc knows to process the file.

  3. The following user says thank you to squidge for this useful post:

    jeffmetal (21st April 2010)

  4. #3
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error calling method using connect

    That fixed it many thanks for the help

    Qt Code:
    1. #ifndef SERVERDIALOG_H
    2. #define SERVERDIALOG_H
    3.  
    4. #include "ui_serverDialog.h"
    5.  
    6. class ServerDialog: public QDialog, public Ui::Dialog
    7.  
    8. {
    9. Q_OBJECT
    10. public:
    11. ServerDialog();
    12. public slots:
    13. void SaveSettings();
    14.  
    15. };
    16.  
    17. #endif // SERVERDIALOG_H
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error calling method using connect

    This was created using Qtcreator.
    if i change the slot to close() it works perfectly. how would i get the method SaveSettings to run.
    Out of interest, how did the close slot work without Q_OBJECT being present?

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error calling method using connect

    Quote Originally Posted by JD2000 View Post
    Out of interest, how did the close slot work without Q_OBJECT being present?
    'Close' is part of QDialog, rather than part of ServerDialog.

  7. The following user says thank you to squidge for this useful post:

    JD2000 (22nd April 2010)

Similar Threads

  1. Compiler error when calling QObject::connect. What am I missing?
    By themanwiththequestion in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2010, 14:33
  2. Replies: 1
    Last Post: 30th March 2009, 16:07
  3. Calling same method from separate threads
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2007, 08:55
  4. Calling Recursivly loading function in Run() method of QThread
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 14:42
  5. Replies: 4
    Last Post: 10th March 2007, 18:01

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.