The example breaks building 6.7 with examples on Android, due to QObject::connect() to a lambda without context object. Add context object. Fixes: QTBUG-123989 Pick-to: 6.6 6.5 6.2 Change-Id: Id3994e577a8a676220ac8d9f95d01c054839c143 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit f54953a0abfe7db796a294c9239b943ebec91a2f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
// Copyright (C) 2021 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#include "notificationclient.h"
|
|
|
|
#include <QApplication>
|
|
#include <QWidget>
|
|
#include <QPushButton>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QFont>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication a(argc, argv);
|
|
|
|
QWidget widget;
|
|
QPushButton happyButton;
|
|
happyButton.setIcon(QIcon(":/images/happy.png"));
|
|
happyButton.setIconSize(QSize(happyButton.width(), 120));
|
|
|
|
QPushButton sadButton;
|
|
sadButton.setIcon(QIcon(":/images/sad.png"));
|
|
sadButton.setIconSize(QSize(sadButton.width(), 120));
|
|
|
|
QVBoxLayout mainLayout;
|
|
QHBoxLayout labelLayout;
|
|
QLabel label = QLabel("Click a smiley to notify your mood");
|
|
QFont font = label.font();
|
|
font.setPointSize(20);
|
|
label.setFont(font);
|
|
labelLayout.addWidget(&label);
|
|
labelLayout.setAlignment(Qt::AlignHCenter);
|
|
mainLayout.addLayout(&labelLayout);
|
|
|
|
QHBoxLayout smileysLayout;
|
|
smileysLayout.addWidget(&sadButton);
|
|
smileysLayout.addWidget(&happyButton);
|
|
smileysLayout.setAlignment(Qt::AlignCenter);
|
|
mainLayout.addLayout(&smileysLayout);
|
|
widget.setLayout(&mainLayout);
|
|
|
|
//! [Connect button signals]
|
|
QObject::connect(&happyButton, &QPushButton::clicked, &happyButton, []() {
|
|
NotificationClient().setNotification("The user is happy!");
|
|
});
|
|
|
|
QObject::connect(&sadButton, &QPushButton::clicked, &happyButton, []() {
|
|
NotificationClient().setNotification("The user is sad!");
|
|
});
|
|
//! [Connect button signals]
|
|
|
|
widget.show();
|
|
return a.exec();
|
|
}
|
|
|