Qt5 信号重载

本篇介绍 Qt5 信号的重载

    radioGroup = new QButtonGroup(this);

    radioGroup->addButton(ui->radioButton1);
    radioGroup->addButton(ui->radioButton2);
    radioGroup->setExclusive(true);

    //old style
    connect(radioGroup,SIGNAL(buttonToggled(int,bool)),this,SLOT(radioGroupToggled()));

    //error
    //    connect(radioGroup,
    //            &QButtonGroup::buttonToggled,
    //            this,
    //            &MainWindow::radioGroupToggled
    //            );

    //Qt help
    //    connect(radioGroup,
    //            QOverload<QAbstractButton *, bool>::of(&QButtonGroup::buttonToggled),
    //            [=](QAbstractButton *button, bool checked){
    //        qDebug() << "button is: " << button << " is checked: " << checked;
    //    });

    //fix1
    //    connect(radioGroup,
    //            QOverload<QAbstractButton *, bool>::of(&QButtonGroup::buttonToggled),
    //            this,
    //            &MainWindow::radioGroupToggled
    //            );

延申阅读

  • Qt5中使用lambda表达式
    https://www.cnblogs.com/yuankaituo/p/5135750.html
  • https://www.devbean.net/2012/05/cpp11-lambda/

C# Lambda 表达式 =>

从简单的例子来看:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string> greet = () => "Hello, World!";
            Console.WriteLine(greet());
            Console.ReadLine();
        }
    }
}

这句

Func<string> greet = () => "Hello, World!";

到底是什么意思?

  • https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/lambda-operator
  • https://blog.csdn.net/zxf347085420/article/details/92803539
  • https://mp.weixin.qq.com/s/1rYTS2iAN17ksHOjCIoE5A