惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 云梦鸿

Winform界面显示的“语言”切换 Linux使用笔记 QT 练习笔记 QT 读写配置文件(*.INI) ubuntu 配置网口静态IP C++ 读写文件 C#编写Windows服务 C#代码计算农历(日期、节气、节日) 中标麒麟,使用笔记 关于无密码访问 Windows7/10 的远程桌面/共享 颜色转换:HSB颜色 与 RGB颜色 QT 给控件(Label)设置显示图片 QT 打包Windows应用程序(*.exe) C#程序执行Python脚本 C#监控U盘插拔 C# AnimateWindow 设置窗体动画 C# GetWindowRect 获取窗体在屏幕中的位置信息 C# 创建音频WAVE文件头信息(*.wav) VS2019错误:CS8370 的处理方法
QT 信号(槽)绑定的使用_connect
云梦鸿 · 2021-12-09 · via 博客园 - 云梦鸿

第一种方式:

 connect(ui->rbtnRed,SIGNAL(clicked()),this,SLOT(setTextFontColor()));

说明:

ui->rbtnRed,是界面上的控件,即发出信号的主体;

clicked(),是对应控件的信号(鼠标点击);

this,即当前窗口对象,指槽函数所属对象(处理信号的主体);

setTextFontColor(),是自定义的槽函数,定义如下(Dialog.h):

private slots:
    void setTextFontColor();

槽函数的具体实现(Dialog.cpp):

void Dialog::setTextFontColor()
{
    QPalette plet=ui->txtEdit->palette();
    if(ui->rbtnBlue->isChecked())
        plet.setColor(QPalette::Text,Qt::blue);
    else if(ui->rbtnRed->isChecked())
        plet.setColor(QPalette::Text,Qt::red);
    else if(ui->rbtBlack->isChecked())
        plet.setColor(QPalette::Text,Qt::black);

    ui->txtEdit->setPalette(plet);
}

第二种方式:

    connect(ui->rbtnRed,&QRadioButton::clicked,[this]{

        QPalette plet=ui->txtEdit->palette();
        if(ui->rbtnBlue->isChecked())
            plet.setColor(QPalette::Text,Qt::blue);
        else if(ui->rbtnRed->isChecked())
            plet.setColor(QPalette::Text,Qt::red);
        else if(ui->rbtBlack->isChecked())
            plet.setColor(QPalette::Text,Qt::black);

        ui->txtEdit->setPalette(plet);
    });

说明:这里将槽函数部分进行简略书写,这样可以不用提前定义一个槽函数,而是直接编写函数实现。

如果信号标签中带参数:

    connect(ui->chkUnderline,&QCheckBox::clicked,[this](bool checked){
        QFont font = ui->txtEdit->font();
        font.setUnderline(checked);

        ui->txtEdit->setFont(font);
    });

如果信号发送主体和接收主体,不再同一个线程中创建,则需要使用(跨)线程同步标记:

    connect(this,   &SystemSync::sendData_UDP,   _SystemUart,  &SystemUart::sendData_UDP,   Qt::QueuedConnection);