Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
src_corelib_kernel_qcoreapplication.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
undef
QT_NO_FOREACH
// this file contains unported legacy Q_FOREACH uses
5
6
#
include
<
QCoreApplication
>
7
#
include
<
QMouseEvent
>
8
#
include
<
QPointF
>
9
#
include
<
QObject
>
10
11
#
if
__has_include
(
<
QtWidgets
>
)
12
#
include
<
QPushButton
>
13
void
example(QPointF &localPos, QPointF &globalPos, QObject *mainWindow, QObject app)
14
{
15
//! [0]
16
QMouseEvent event(QEvent::MouseButtonPress, localPos, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
17
QCoreApplication::sendEvent(mainWindow, &event);
18
//! [0]
19
20
//! [1]
21
QPushButton *quitButton =
new
QPushButton(
"Quit"
);
22
QObject::connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection);
23
//! [1]
24
}
25
#
endif
26
27
class
MyDebugTool
:
public
QObject
28
{
29
public
:
30
MyDebugTool
(QObject *parent =
nullptr
) :
QObject
(
parent
) {}
31
};
32
33
//! [3]
34
// Called once QCoreApplication exists
35
static
void
preRoutineMyDebugTool
()
36
{
37
MyDebugTool
* tool =
new
MyDebugTool(QCoreApplication::instance());
38
QCoreApplication::instance()->installEventFilter(tool);
39
}
40
41
Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool)
42
//! [3]
43
44
45
//! [4]
46
static
int
*
global_ptr
=
nullptr
;
47
48
static
void
cleanup_ptr
()
49
{
50
delete
[]
global_ptr
;
51
global_ptr
=
nullptr
;
52
}
53
54
void
init_ptr
()
55
{
56
global_ptr
=
new
int
[100];
// allocate data
57
qAddPostRoutine(
cleanup_ptr
);
// delete later
58
}
59
//! [4]
60
61
62
//! [5]
63
class
MyPrivateInitStuff
:
public
QObject
64
{
65
public
:
66
static
MyPrivateInitStuff
*
initStuff
(QObject *parent)
67
{
68
if
(!p)
69
p =
new
MyPrivateInitStuff
(parent);
70
return
p;
71
}
72
73
~
MyPrivateInitStuff
()
74
{
75
// cleanup goes here
76
}
77
78
private
:
79
MyPrivateInitStuff(QObject *parent)
80
: QObject(parent)
81
{
82
// initialization goes here
83
}
84
85
static
MyPrivateInitStuff
*p;
86
};
87
//! [5]
88
89
90
//! [6]
91
static
inline
QString
tr
(
const
char
*sourceText,
92
const
char
*comment =
nullptr
);
93
//! [6]
94
95
class
CView
{};
96
97
//! [7]
98
class
MyMfcView
:
public
CView
99
{
100
Q_DECLARE_TR_FUNCTIONS
(
MyMfcView
)
101
102
public
:
103
MyMfcView
();
104
//...
105
};
106
//! [7]
CView
[6]
Definition
src_corelib_kernel_qcoreapplication.cpp:95
MyDebugTool
Definition
src_corelib_kernel_qcoreapplication.cpp:28
MyDebugTool::MyDebugTool
MyDebugTool(QObject *parent=nullptr)
Definition
src_corelib_kernel_qcoreapplication.cpp:30
MyMfcView
[7]
Definition
src_corelib_kernel_qcoreapplication.cpp:99
MyPrivateInitStuff
[4]
Definition
src_corelib_kernel_qcoreapplication.cpp:64
MyPrivateInitStuff::initStuff
static MyPrivateInitStuff * initStuff(QObject *parent)
Definition
src_corelib_kernel_qcoreapplication.cpp:66
MyPrivateInitStuff::~MyPrivateInitStuff
~MyPrivateInitStuff()
Definition
src_corelib_kernel_qcoreapplication.cpp:73
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
cleanup_ptr
static void cleanup_ptr()
Definition
src_corelib_kernel_qcoreapplication.cpp:48
tr
static QString tr(const char *sourceText, const char *comment=nullptr)
[5]
preRoutineMyDebugTool
static void preRoutineMyDebugTool()
[3]
Definition
src_corelib_kernel_qcoreapplication.cpp:35
global_ptr
static int * global_ptr
[3]
Definition
src_corelib_kernel_qcoreapplication.cpp:46
init_ptr
void init_ptr()
Definition
src_corelib_kernel_qcoreapplication.cpp:54
qtbase
src
corelib
doc
snippets
code
src_corelib_kernel_qcoreapplication.cpp
Generated on
for Qt by
1.18.0