QObject :: connect:没有这样的插槽(Qt,C ++) [英] QObject::connect: No such slot (Qt, C++)
本文介绍了QObject :: connect:没有这样的插槽(Qt,C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以运行该程序,但是该按钮无法访问发送功能。我得到这个提示:
I can run the program but the button cannot access the send function. I get this hint:
QObject :: connect:没有这样的插槽Mail :: send(emailInput,pwdInput)
QObject::connect: No such slot Mail::send(emailInput, pwdInput)
有人知道我的错误吗?
mail.h:
#ifndef MAIL_H
#define MAIL_H
#include <QWidget>
namespace Ui {
class Mail;
}
class Mail : public QWidget
{
Q_OBJECT
public:
explicit Mail(QWidget *parent = 0);
~Mail();
public slots:
void send(std::string email, std::string pwd);
private:
Ui::Mail *ui;
};
#endif // MAIL_H
mail.cpp:
Mail::Mail(QWidget *parent) :
QWidget(parent)
{
QLineEdit *edt1 = new QLineEdit(this);
grid->addWidget(edt1, 0, 1, 1, 1);
std::string emailInput = edt1->text().toStdString();
...
QObject::connect(acc, SIGNAL(clicked()),this, SLOT(send(emailInput, pwdInput)));
}
void Mail::send(std::string email, std::string pwd){
...
}
推荐答案
实际上,您的代码中有2个错误:
In fact, you have 2 mistakes in your code:
- SLOT宏将参数类型作为参数而不是其名称作为参数,则代码应为:
SLOT(send( std :: string,std :: string))
。 - 您尝试连接参数小于SLOT的信号,而这是不可能的。
为了避免所有这些问题,您可以使用新的信号/插槽语法(如果您使用的是Qt5):
In order to avoid all these problems you can use the new signal/slot syntax (if your are using Qt5):
QObject::connect(acc, &QLineEdit::clicked, this, &Mail::onClicked);
我还邀请您在使用Qt时使用QString类而不是std :: string,它容易得多。
I also invite you to use the QString class instead of std::string when working with Qt, it is a lot easier.
这篇关于QObject :: connect:没有这样的插槽(Qt,C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文