Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qglobal.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2017 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qplatformdefs.h"
6#include "qstring.h"
7#include "qbytearrayview.h"
8#include "qlist.h"
9#include "qdir.h"
10#include "qdatetime.h"
11#include <private/qlocale_tools_p.h>
12#include "qnativeinterface.h"
13#include "qnativeinterface_p.h"
14
15#ifdef Q_OS_WIN
16# include <qt_windows.h>
17#endif
18
19#if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL)
20# include <envLib.h>
21#endif
22
23#if defined(Q_OS_INTEGRITY)
24extern "C" {
25 // Function mmap resides in libshm_client.a. To be able to link with it one needs
26 // to define symbols 'shm_area_password' and 'shm_area_name', because the library
27 // is meant to allow the application that links to it to use POSIX shared memory
28 // without full system POSIX.
29# pragma weak shm_area_password
30# pragma weak shm_area_name
31 char shm_area_password[] = "dummy";
32 char shm_area_name[] = "dummy";
33}
34#endif
35
37
38using namespace Qt::StringLiterals;
39
93/*
94 Dijkstra's bisection algorithm to find the square root of an integer.
95 Deliberately not exported as part of the Qt API, but used in
96 qtextdocument.cpp.
97*/
98Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n)
99{
100 // n must be in the range 0...UINT_MAX/2-1
101 if (n >= (UINT_MAX >> 2)) {
102 unsigned int r = 2 * qt_int_sqrt(n / 4);
103 unsigned int r2 = r + 1;
104 return (n >= r2 * r2) ? r2 : r;
105 }
106 uint h, p = 0, q = 1, r = n;
107 while (q <= n)
108 q <<= 2;
109 while (q != 1) {
110 q >>= 2;
111 h = p + q;
112 p >>= 1;
113 if (r >= h) {
114 p += q;
115 r -= h;
116 }
117 }
118 return p;
119}
120
121// Also specified to behave as if they call tzset():
122// localtime() -- but not localtime_r(), which we use when threaded
123// strftime() -- not used (except in tests)
124
126{
127 QList<QList<qInternalCallback>> callbacks;
128};
129
130Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
131
132bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
133{
134 if (unsigned(cb) < unsigned(QInternal::LastCallback)) {
135 QInternal_CallBackTable *cbt = global_callback_table();
136 cbt->callbacks.resize(cb + 1);
137 cbt->callbacks[cb].append(callback);
138 return true;
139 }
140 return false;
141}
142
144{
145 if (unsigned(cb) < unsigned(QInternal::LastCallback)) {
146 if (global_callback_table.exists()) {
147 QInternal_CallBackTable *cbt = global_callback_table();
148 return cbt->callbacks[cb].removeAll(callback) > 0;
149 }
150 }
151 return false;
152}
153
155{
156 Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
157
158 if (!global_callback_table.exists())
159 return false;
160
161 QInternal_CallBackTable *cbt = &(*global_callback_table);
162 if (cbt && cb < cbt->callbacks.size()) {
163 QList<qInternalCallback> callbacks = cbt->callbacks[cb];
164 bool ret = false;
165 for (int i = 0; i < callbacks.size(); ++i)
166 ret |= (callbacks.at(i))(parameters);
167 return ret;
168 }
169 return false;
170}
171
372namespace QtPrivate {
373Q_LOGGING_CATEGORY(lcNativeInterface, "qt.nativeinterface")
374}
375
static bool unregisterCallback(Callback, qInternalCallback)
Definition qglobal.cpp:143
static bool activateCallbacks(Callback, void **)
Definition qglobal.cpp:154
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
#define Q_DECL_CONST_FUNCTION
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n)
\inmodule QtCore \title Global Qt Declarations
Definition qglobal.cpp:98
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
return ret
bool(* qInternalCallback)(void **)
GLboolean r
[2]
GLfloat n
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
PromiseCallbacks callbacks
Definition qstdweb.cpp:275
unsigned int uint
Definition qtypes.h:34
QRect r2(QPoint(100, 200), QSize(11, 16))
QList< QList< qInternalCallback > > callbacks
Definition qglobal.cpp:127