Qt_GUI_BG_3_2 - 8BitsCoding/RobotMentor GitHub Wiki

String Notation

connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(changeText()));

Functor Notation

connect(ui->pushButton, &QPushButton::clicked, this, &MyWidget::changeText);

Functor Lambda Notation

connect(ui->pushButton, &QPushButton::clickec, [=]{ui->label->setText("Get Lost");});

Example

// .h
#pragma once

#include <QtWidgets/QWidget>
#include "ui_QtGuiApplication4.h"

class QtGuiApplication4 : public QWidget
{
	Q_OBJECT

public:
	QtGuiApplication4(QWidget *parent = Q_NULLPTR);

private:
	Ui::QtGuiApplication4Class ui;

private slots:
	void changeText();
};
// .cpp
#include "QtGuiApplication4.h"

#include <qpushbutton.h>
#include <qdebug.h>

QtGuiApplication4::QtGuiApplication4(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);

	
	// String Notation
	connect(ui.pushButton, SIGNAL(clicked()),
		this, SLOT(changeText()));
	

	
	// Functor Notation : Regular Slots
	connect(ui.pushButton, &QPushButton::clicked,
		this, &QtGuiApplication4::changeText);
	

	// Functor Notation : Lambdas
	connect(ui.pushButton, &QPushButton::clicked,
		[=]() {
		ui.label->setText("Lambda");
	});
}


void QtGuiApplication4::changeText()
{
	qDebug() << "User Clicke Button";
	ui.label->setText("Hello There");
}
⚠️ **GitHub.com Fallback** ⚠️