Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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>
13void 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
27class MyDebugTool : public QObject
28{
29 public:
30 MyDebugTool(QObject *parent = nullptr) : QObject(parent) {}
31};
32
33//! [3]
34// Called once QCoreApplication exists
36{
37 MyDebugTool* tool = new MyDebugTool(QCoreApplication::instance());
38 QCoreApplication::instance()->installEventFilter(tool);
39}
40
41Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool)
42//! [3]
43
44
45//! [4]
46static int *global_ptr = nullptr;
47
48static void cleanup_ptr()
49{
50 delete [] global_ptr;
51 global_ptr = nullptr;
52}
53
55{
56 global_ptr = new int[100]; // allocate data
57 qAddPostRoutine(cleanup_ptr); // delete later
58}
59//! [4]
60
61
62//! [5]
64{
65public:
66 static MyPrivateInitStuff *initStuff(QObject *parent)
67 {
68 if (!p)
69 p = new MyPrivateInitStuff(parent);
70 return p;
71 }
72
74 {
75 // cleanup goes here
76 }
77
78private:
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]
91static inline QString tr(const char *sourceText,
92 const char *comment = nullptr);
93//! [6]
94
95class CView {};
96
97//! [7]
98class MyMfcView : public CView
99{
101
102public:
104 //...
105};
106//! [7]
MyDebugTool(QObject *parent=nullptr)
static MyPrivateInitStuff * initStuff(QObject *parent)
#define __has_include(x)
static void cleanup_ptr()
static QString tr(const char *sourceText, const char *comment=nullptr)
[5]
static void preRoutineMyDebugTool()
[3]
static int * global_ptr
[3]