C++ QObject::connect:没有这样的插槽(Qt、C+;+;)
我可以运行程序,但按钮无法访问发送功能。我得到这个暗示: QObject::connect:没有这样的插槽Mail::send(emailInput,pwdInput) 有人知道我犯了什么错 邮件.h:C++ QObject::connect:没有这样的插槽(Qt、C+;+;),c++,qt,connect,slot,C++,Qt,Connect,Slot,我可以运行程序,但按钮无法访问发送功能。我得到这个暗示: QObject::connect:没有这样的插槽Mail::send(emailInput,pwdInput) 有人知道我犯了什么错 邮件.h: #ifndef MAIL_H #define MAIL_H #include <QWidget> namespace Ui { class Mail; } class Mail : public QWidget { Q_OBJECT public: expli
#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
这取决于你想做什么: 如果
emailInput
和pwdInput
来自widgets,则必须编写一个中间槽来获取值并调用send
如果它们是局部变量,最简单的方法可能是使用lambda。这取决于您要执行的操作: 如果
emailInput
和pwdInput
来自widgets,则必须编写一个中间槽来获取值并调用send
如果它们是局部变量,最简单的方法可能是使用lambda。应该是
QObject::connect(acc, SIGNAL(clicked()),this, SLOT(send(std::string, std::string)));
宏SIGNAL
和SLOT
期望方法的签名作为参数
此外,您可以将信号连接到一个少arity的插槽,反之亦然;在这里,QObject不会简单地知道应该用什么来代替slot的参数。您可以使用connect
的重载,该重载接受任意Functor
(很可能是匿名闭包)作为插槽:
第三,如果您使用QString
而不是std::string
,那么在传递值时就不会有那么大的复制开销
QObject::connect(acc, SIGNAL(clicked()),this, SLOT(send(std::string, std::string)));
宏SIGNAL
和SLOT
期望方法的签名作为参数
此外,您可以将信号连接到一个少arity的插槽,反之亦然;在这里,QObject不会简单地知道应该用什么来代替slot的参数。您可以使用connect
的重载,该重载接受任意Functor
(很可能是匿名闭包)作为插槽:
第三,如果您使用
QString
而不是std::string
,那么在传递值时就不会有那么大的复制开销。事实上,您的代码中有两个错误:
SLOT(send(std::string,std::string))
我还邀请您在使用Qt时使用QString类而不是std::string,这要容易得多。事实上,您的代码中有两个错误:
SLOT(send(std::string,std::string))
我还邀请您在使用Qt时使用QString类而不是std::string,这要容易得多。您的语法错误。您需要
SLOT(send(std::string,std::string))
您的语法错误。你想要SLOT(send(std::string,std::string))
刚刚编辑了这篇文章。我想将文本保存在QLineEdit中,然后使用变量调用send。然后,您必须编写第一个插槽,该插槽不带任何参数,并连接到按钮的单击信号,然后使用实际值调用send(或者在lambda中执行此操作,但可能会非常混乱^^^),只需编辑帖子即可。我想将文本保存在QLineEdit中,然后使用变量调用send。然后,您必须编写第一个插槽,该插槽不带任何参数,并连接到按钮的单击信号,然后使用实际值调用send(或者在lambda中执行此操作,但它可能非常混乱^^)
QObject::connect(acc, SIGNAL(clicked()), [=](){ send(std::string(), std::string()); });
QObject::connect(acc, &QLineEdit::clicked, this, &Mail::onClicked);