macOS 10.15 Qt connect: No such signal QPushButton::cliked()

2019-10-27 17:44:23 +08:00
 contersion

.h


#include <QObject>
#include <QWidget> 
#include <QLabel>  
#include <QVBoxLayout> 
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>

class my_Widget : public QWidget
{
    Q_OBJECT

    QLabel *label;
    bool flag;

public:
    my_Widget(QWidget *parent = nullptr);
    ~my_Widget();

public slots:
    void slots_trans();
};


.c


my_Widget::my_Widget(QWidget *parent)
    : QWidget(parent)
{

    this->setWindowTitle("hello");
    this->resize(200,100);

    label = new QLabel("你好,世界!");
    flag = true;

    QPushButton *button = new QPushButton;

    button->setText("翻译");

    label->setAlignment(Qt::AlignHCenter);

    QVBoxLayout  *layout = new QVBoxLayout(this);
    layout->addWidget(label);
    layout->addWidget(button);

    connect(button,SIGNAL(cliked()),this,SLOT(slots_trans));
}

my_Widget::~my_Widget()
{

}

void my_Widget::slots_trans()
{
    if(flag == true)
        label->setText("Hello,World!");
    else {
        label->setText("你好,世界!");
    }
    flag = !flag;
}

同样的代码在 win 下可以运行,在 macos 下就会报错


QObject::connect: No such signal QPushButton::cliked() in ../PrintHello/my_widget.cpp:23

初学 qt,希望各位大佬能帮帮忙,谢谢

1777 次点击
所在节点    问与答
3 条回复
wbing
2019-10-27 18:01:40 +08:00
cliked 拼错了,是 clicked
contersion
2019-10-27 18:30:56 +08:00
@wbing 非常感谢,clicked 我在 SIGNAL 不能自动补全,要手打,这是什么原因呢
luassuns
2019-10-27 23:13:00 +08:00
@contersion #2 你用的是 SINGAL()的写法编辑器估计不支持提示,你可以试试 button::clicked 会不会出提示。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/613428

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX