您当前的位置: 首页 >  c++

*DDL_GzmBlog

暂无认证

  • 2浏览

    0关注

    605博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[C++ 小学期] Qt 第二课

*DDL_GzmBlog 发布时间:2021-06-16 13:57:37 ,浏览量:2

目录
  • 带参数的信号
  • Lamba表达式 匿名函数对象
  • 各种栏
    • 菜单栏
    • 工具栏
    • 状态栏

带参数的信号

QString 相当于 c++ 中的string

void Mysignal(int,QString);

可以重载 重载的链接处理

  • 使用函数指针
void (xd::*fun1)() = &xd::Mysignal;
void (xd::*fun2)(int,QString) = &xd::Mysignal;
connect(&w,fun1,this,&Widget::dealSub);

connect(&w,fun2,this,&Widget::dealSlot);
Lamba表达式 匿名函数对象
  • []外部变量的传值

  • 如果[=] 表示全部外部变量 以值传递方式

  • 如果需要修改 需要加一个mutable

//Lamba表达式 匿名函数对象
QPushButton *nb1 =  new QPushButton(this);
nb1->setText("dontknow");

//[=] : 把外部所有局部变量,类中所有成员以值传递方式传递进来
connect(nb1,&QPushButton::released,
[nb1]() //mutable 将值传递破解
//[]代表函数的开始 ()参数
{
    //[]把外部变量传进来
    nb1->setText("123");
   
}

);
各种栏
  • 菜单栏
  • 工具栏
  • 状态栏
  • 核心空间
  • 浮动窗口
菜单栏

头文件

#include 
#include 

新建菜单栏

QMenuBar *mBar =menuBar();

新建菜单项

   QAction *pNew = pFile->addAction("新建");

然后就是匿名函数

QAction 所以用 triggered

connect(pNew,&QAction::triggered,
        [=]()
         {
            qDebug()addAction(pNew);
状态栏
#include 
#include 

定义和使用:

   QStatusBar *statuBar = statusBar();
   QLabel *label = new QLabel(this);
   label->setText("Normal");
   statuBar->addWidget(label);
关注
打赏
1657615554
查看更多评论
立即登录/注册

微信扫码登录

0.0403s