PDA

View Full Version : error calling method using connect



jeffmetal
21st April 2010, 20:41
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



Object::connect: No such slot QDialog::SaveSettings() in serverDialog.cpp:6
Object::connect: (sender name: 'pushButton_Save')
Object::connect: (receiver name: 'Dialog')




#ifndef SERVERDIALOG_H
#define SERVERDIALOG_H

#include "ui_serverDialog.h"

class ServerDialog: public QDialog, public Ui::Dialog
{
public:
ServerDialog();
protected slots:
void SaveSettings();

};

#endif // SERVERDIALOG_H




#include "serverDialog.h"

ServerDialog::ServerDialog()
{
setupUi(this);
connect(pushButton_Save, SIGNAL(clicked()), this, SLOT(SaveSettings()));
connect(pushButton_Quit, SIGNAL(clicked()), this, SLOT(close()));
}

void ServerDialog::SaveSettings()
{


}


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

squidge
21st April 2010, 22:43
Try adding the line "Q_OBJECT" before "public:" so moc knows to process the file.

jeffmetal
21st April 2010, 23:01
That fixed it many thanks for the help



#ifndef SERVERDIALOG_H
#define SERVERDIALOG_H

#include "ui_serverDialog.h"

class ServerDialog: public QDialog, public Ui::Dialog

{
Q_OBJECT
public:
ServerDialog();
public slots:
void SaveSettings();

};

#endif // SERVERDIALOG_H

JD2000
22nd April 2010, 16:05
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?

squidge
22nd April 2010, 18:09
Out of interest, how did the close slot work without Q_OBJECT being present?

'Close' is part of QDialog, rather than part of ServerDialog.