1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "abstractconsole.h" |
6 | |
7 | #include <QWidget> |
8 | #include <QDebug> |
9 | |
10 | class AbstractConsolePrivate |
11 | { |
12 | friend class AbstractConsole; |
13 | QWidget *qWidget = nullptr; |
14 | }; |
15 | |
16 | AbstractConsole::AbstractConsole(void *qWidget) |
17 | : d(new AbstractConsolePrivate) |
18 | { |
19 | if (!qWidget) { |
20 | qCritical() << "Failed, use QWidget(0x0) to AbstractWidget"; |
21 | abort(); |
22 | } |
23 | |
24 | d->qWidget = static_cast<QWidget*>(qWidget); |
25 | d->qWidget->connect(d->qWidget, &QWidget::destroyed, |
26 | d->qWidget, [this](QObject *obj){ |
27 | if (obj == d->qWidget) { |
28 | qInfo() << "AbstractConsole QWidget::destroyed"<< obj; |
29 | delete this; |
30 | } |
31 | }, Qt::DirectConnection); |
32 | } |
33 | |
34 | AbstractConsole::~AbstractConsole() |
35 | { |
36 | if (d) { |
37 | delete d; |
38 | } |
39 | } |
40 | |
41 | void *AbstractConsole::qWidget() |
42 | { |
43 | return d->qWidget; |
44 | } |
45 | |
46 |