PDA

View Full Version : "no matching function for call to 'UserCreationDialog::Connect(..."



Leutzig
12th April 2016, 11:06
Hi,

I have two classes, UserConfiguration and UserCreationDialog, in my C++ Qt Project. I need to make a connection between a signal from UserCreationDialog, when OK button is pressed and the slot update() in UserConfiguration. The connection is seen in my code below. But when I build, I get the error:



"[...] usercreationdialog.cpp:13: error: no matching function for call to 'UserCreationDialog::connect(UserCreationDialog*, const char*, UserConfiguration**, const char*)' connect(this, SIGNAL(updateUserConfig()),&uconf,SLOT(update()));"
^

UserCreationDialog.h


#ifndef USERCREATIONDIALOG_H
#define USERCREATIONDIALOG_H
#include <QDialog>

class UserConfiguration;

namespace Ui {
class UserCreationDialog;
}

class UserCreationDialog : public QDialog
{
Q_OBJECT

public:
explicit UserCreationDialog(QWidget *parent = 0);
~UserCreationDialog();

private slots:
void on_buttonBox_accepted();

private:
Ui::UserCreationDialog *ui;
UserConfiguration *uconf;
QSqlDatabase* fv_db;

signals:
void updateUserConfig();
};

#endif // USERCREATIONDIALOG_H


UserCreationDialog.cpp


#include "usercreationdialog.h"
#include "ui_usercreationdialog.h"
#include "userconfiguration.h"

UserCreationDialog::UserCreationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UserCreationDialog)
{
ui->setupUi(this);

connect(this, SIGNAL(updateUserConfig()),&uconf,SLOT(update()));
}

UserCreationDialog::~UserCreationDialog()
{
delete ui;
}

void UserCreationDialog::on_buttonBox_accepted()
{
QString uid = ui->userIDLineEdit->text();
QString pw = ui->passwordLineEdit->text();
writeUserToDb(uid,pw, *fv_db);
emit updateUserConfig();
close();
}


Some irrelevant code is left out from the shown code above.

// Leutzig

anda_skoa
12th April 2016, 11:34
"uconf" already is a pointer, the & in your connect() call makes it a pointer to a pointer.

Cheers,
_

Leutzig
12th April 2016, 13:17
Thanks anda_skoa :)

Added after 1 33 minutes:

I actually have a different problem with my connect(). I got rid of the error before but now my application crashes when it reaches the connect(), and I get the message "The program has unexpectedly finished". Am I connecting my signal and slot correctly or?

UserCreationDialog.h


#ifndef USERCREATIONDIALOG_H
#define USERCREATIONDIALOG_H

#include <QDialog>
#include "dbinterface.h"

class UserConfiguration;

namespace Ui {
class UserCreationDialog;
}

class UserCreationDialog : public QDialog
{
Q_OBJECT

public:
explicit UserCreationDialog(QWidget *parent = 0);
~UserCreationDialog();

private slots:
void on_buttonBox_accepted();

private:
Ui::UserCreationDialog *ui;
UserConfiguration *uconf;
QSqlDatabase* fv_db;

signals:
void updateUserConfig();
};

#endif // USERCREATIONDIALOG_H


UserCreationDialog.cpp


#include "usercreationdialog.h"
#include "ui_usercreationdialog.h"
#include "userconfiguration.h"

UserCreationDialog::UserCreationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UserCreationDialog)
{
ui->setupUi(this);

connect(this, SIGNAL(updateUserConfig()), uconf, SLOT(updateUC()));
}

UserCreationDialog::~UserCreationDialog()
{
delete ui;
}

void UserCreationDialog::on_buttonBox_accepted()
{
QString uid = ui->userIDLineEdit->text();
QString pw = ui->passwordLineEdit->text();
writeUserToDb(uid,pw, *fv_db);
emit updateUserConfig();
delete this;
}


The slot updateUConf() is found in the UserConfiguration class, so no need to show that.

// Leutzig

d_stranz
12th April 2016, 15:43
And where do you set the value of "uconf" that is used in your connect() statement? As far as I can see in your code, it is an uninitialized pointer.

Leutzig
12th April 2016, 17:39
That's right, I haven't initialized the pointer. Thanks :)

// Leutzig