No such slot Window::signUp(username,password,passwordRepeat)
-
Hi,
I don't know why but my qt shows
No such slot Window::signUp(username,password,passwordRepeat) error
this is my code
window.cpp#include <QApplication> #include <QPushButton> #include <QLineEdit> #include <QMessageBox> #include <window.h> void Window::signUp(QString username,QString password,QString passwordRepeat){ QMessageBox msgBox; msgBox.setText("Username :"+username+" password :"+password +" password repeat :"+passwordRepeat); msgBox.exec(); msgBox.show(); } Window::Window(QWidget *parent) : QWidget(parent) { setFixedSize(400,400); usernameLine = new QLineEdit(this); usernameLine->setGeometry(100,50,200,30); usernameLine->setPlaceholderText("username"); QString username = usernameLine->text(); passwordLine = new QLineEdit(this); passwordLine->setPlaceholderText("password"); passwordLine->setGeometry(100,90,200,30); QString password = passwordLine->text(); passwordRepeatLine = new QLineEdit(this); passwordRepeatLine->setPlaceholderText("password repeat"); passwordRepeatLine->setGeometry(100,130,200,30); QString passwordRepeat = passwordRepeatLine->text(); button = new QPushButton("Submit",this); button->setGeometry(150,180,100,30); QObject::connect(button, SIGNAL(clicked()),this, SLOT(signUp(username,password,passwordRepeat))); }
window.h
#ifndef MAIN_H #define MAIN_H #include <QWidget> class QPushButton; class QLineEdit; class Window : public QWidget { Q_OBJECT public: explicit Window(QWidget *parent = 0); /*signals: public slots:*/ private: QPushButton *button; QLineEdit *usernameLine; QLineEdit *passwordLine; QLineEdit *passwordRepeatLine; public slots: void signUp(QString,QString,QString); }; #endif
Why am I getting no such slot when I already declared slot in header file?
-
Just remove the parameters of your slot and retrieve there the values you need.
-
Hi,
Because you are passing arguments and not the correct signature.
You should use the new syntax so you will get compile time error rather than runtime.
-
Hi,
Because you are passing arguments and not the correct signature.
You should use the new syntax so you will get compile time error rather than runtime.
@SGaist
Unfortunately I don't think I can use new syntax for this project. Link I got from my professor does not use a new syntax if I guess right. Can't it be done with old syntax? -
Sure it can be done, but not the way you do it. You cannot connect a slot that has more parameters than the signal you are connecting from.
Which version of Qt are you using by the way ?
-
Sure it can be done, but not the way you do it. You cannot connect a slot that has more parameters than the signal you are connecting from.
Which version of Qt are you using by the way ?
@SGaist I am using qmake version 3.0
I understand what you mean, so I tried
QObject::connect(button, SIGNAL(clicked(username,password,passwordRepeat)),this, SLOT(signUp(username,password,passwordRepeat)));
But it shows
QObject::connect: No such signal QPushButton::clicked(username,password,passwordRepeat)I guess I have to create custom clicked signal in header file, isn't it?
-
@SGaist I am using qmake version 3.0
I understand what you mean, so I tried
QObject::connect(button, SIGNAL(clicked(username,password,passwordRepeat)),this, SLOT(signUp(username,password,passwordRepeat)));
But it shows
QObject::connect: No such signal QPushButton::clicked(username,password,passwordRepeat)I guess I have to create custom clicked signal in header file, isn't it?
@progloveprog
You have to write the types of the parameters where you have written parameter names, in theSIGNAL
&SLOT()
macros.But you also cannot "invent" that an existing signal, like
QPushButton::clicked()
, passes extra parameters like you have done. It does not pass those.I guess I have to create custom clicked signal in header file, isn't it?
If you do it that way then yes you would need to do that. There are different ways, but we don't know what "your professor" is wanting you to do here :)
-
Just remove the parameters of your slot and retrieve there the values you need.
-
@SGaist
Thank you
That was the right way to go hahaha
I didn't think it would be possible to read text of UI from outside of Window::Window