Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 6886b0b

Browse files
author
mttwc
committed
Demonstrates disconnecting
1 parent 9918f43 commit 6886b0b

File tree

6 files changed

+66
-39
lines changed

6 files changed

+66
-39
lines changed

HelloQt.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
QT += widgets
77

88
SOURCES = src/main.cpp \
9-
src/move_demonstration.cpp \
9+
src/disconnect_demonstration.cpp \
1010

11-
HEADERS = src/move_demonstration.h
11+
HEADERS = src/disconnect_demonstration.h
1212

1313
CONFIG -= app_bundle
1414

src/disconnect_demonstration.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <QTextStream>
2+
#include <QCheckBox>
3+
#include <QHBoxLayout>
4+
#include "disconnect_demonstration.h"
5+
6+
DisconnectDemonstration::DisconnectDemonstration(QWidget *parent)
7+
: QWidget(parent)
8+
{
9+
QHBoxLayout *hbox = new QHBoxLayout(this);
10+
hbox->setSpacing(5);
11+
12+
clickBtn = new QPushButton("Click", this);
13+
hbox->addWidget(clickBtn, 0, Qt::AlignLeft | Qt::AlignTop);
14+
15+
QCheckBox *cb = new QCheckBox("Connect", this);
16+
cb->setCheckState(Qt::Checked);
17+
hbox->addWidget(cb, 0, Qt::AlignLeft | Qt::AlignTop);
18+
19+
connect(clickBtn, &QPushButton::clicked, this, &DisconnectDemonstration::onClick);
20+
connect(cb, &QCheckBox::stateChanged, this, &DisconnectDemonstration::onCheck);
21+
}
22+
23+
void DisconnectDemonstration::onClick()
24+
{
25+
QTextStream out(stdout);
26+
out << "Button clicked" << endl;
27+
}
28+
29+
void DisconnectDemonstration::onCheck(int state)
30+
{
31+
if (state == Qt::Checked)
32+
{
33+
connect(clickBtn, &QPushButton::clicked, this, &DisconnectDemonstration::onClick);
34+
}
35+
else
36+
{
37+
disconnect(clickBtn, &QPushButton::clicked, this, &DisconnectDemonstration::onClick);
38+
}
39+
}

src/disconnect_demonstration.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef DISCONNECT_DEMONSTRATION_H
2+
#define DISCONNECT_DEMONSTRATION_H
3+
4+
#include <QWidget>
5+
#include <QPushButton>
6+
7+
class DisconnectDemonstration : public QWidget
8+
{
9+
Q_OBJECT
10+
11+
public:
12+
DisconnectDemonstration(QWidget *parent = 0);
13+
14+
private slots:
15+
void onClick();
16+
void onCheck(int);
17+
18+
private:
19+
QPushButton *clickBtn;
20+
};
21+
22+
#endif

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <QApplication>
22
#include <QWidget>
3-
#include "move_demonstration.h"
3+
#include "disconnect_demonstration.h"
44

55
int main(int argc, char *argv[])
66
{
77
QApplication app(argc, argv);
88

9-
MoveDemonstration window;
9+
DisconnectDemonstration window;
1010

1111
window.resize(250, 150);
12-
window.setWindowTitle("Move Event Demonstration");
12+
window.setWindowTitle("Disconnect Demonstration");
1313
window.show();
1414

1515
return app.exec();

src/move_demonstration.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/move_demonstration.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)