### Bug Summary

File: | usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h
Warning: | line 319, column 9 Potential memory leak

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name workspace_state.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-21/lib/clang/21 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore5Compat -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE5COMPAT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=c++17 -fdeprecated-macro -ferror-limit 19 -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2026-03-04-100353-3622-1 -x c++ /builds/wireshark/wireshark/ui/qt/utils/workspace_state.cpp

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

#### /builds/wireshark/wireshark/ui/qt/utils/workspace_state.cpp

→

1 | /* workspace_state.cpp
2 | *
3 | * Wireshark - Network traffic analyzer
4 | * By Gerald Combs <gerald@wireshark.org>
5 | * Copyright 1998 Gerald Combs
6 | *
7 | * SPDX-License-Identifier: GPL-2.0-or-later
8 | */
9 |
10 | #include "config.h"
11 |
12 | #include "workspace_state.h"
13 |
14 | #include <algorithm>
15 | #include <QFile>
16 | #include <QTextStream>
17 | #include <QDir>
18 | #include <QRegularExpression>
19 | #include <QtConcurrent>
20 | #include <QThreadPool>
21 |
22 | #include <wsutil/filesystem.h>
23 | #include <app/application_flavor.h>
24 |
25 | #include <ui/qt/utils/qt_ui_utils.h>
26 | #include <ui/recent.h>
27 | #include <epan/prefs.h>
28 |
29 | WorkspaceState::WorkspaceState(QObject *parent)
30 | : QObject(parent)
31 | {
32 | }
33 |
34 | WorkspaceState::~WorkspaceState()
35 | {
36 | }
37 |
38 | WorkspaceState* WorkspaceState::instance()
39 | {
40 | // Meyer's Singleton - thread-safe in C++11 and later
41 | static WorkspaceState* instance_ = new WorkspaceState();
42 | return instance_;
43 | }
44 |
45 | QString WorkspaceState::recentCommonFilePath() const
46 | {
47 | // recent_common is NOT profile-specific (from_profile = false)
48 | char *rf_path = get_persconffile_path(
49 | RECENT_COMMON_FILE_NAME,
50 | false, // from_profile = false
51 | application_configuration_environment_prefix()
52 | );
53 |
54 | QString path = QString::fromUtf8(rf_path);
55 | g_free(rf_path);
56 |
57 | return path;
58 | }
59 |
60 | QString WorkspaceState::recentProfileFilePath() const
61 | {
62 | // recent is profile-specific (from_profile = true)
63 | char *rf_path = get_persconffile_path(
64 | RECENT_PROFILE_FILE_NAME,
65 | true, // from_profile = true
66 | application_configuration_environment_prefix()
67 | );
68 |
69 | QString path = QString::fromUtf8(rf_path);
70 | g_free(rf_path);
71 |
72 | return path;
73 | }
74 |
75 | bool WorkspaceState::parseRecentFile(const QString &filePath,
76 | std::function<void(const QString &key, const QString &value)> handler)
77 | {
78 | QFile file(filePath);
79 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
80 | return false;
81 | }
82 |
83 | QTextStream in(&file);
84 | // Match: key: value (with optional whitespace)
85 | static const QRegularExpression keyValueRe(QStringLiteral("^([^:]+):\\s*(.*)$")(QString(QtPrivate::qMakeStringPrivate(u"" "^([^:]+):\\s*(.*)$" ))));
86 |
87 | while (!in.atEnd()) {
88 | QString line = in.readLine();
89 |
90 | // Skip empty lines and comments
91 | if (line.isEmpty() || line.startsWith('#')) {
92 | continue;
93 | }
94 |
95 | QRegularExpressionMatch match = keyValueRe.match(line);
96 | if (match.hasMatch()) {
97 | QString key = match.captured(1).trimmed();
98 | QString value = match.captured(2);
99 | handler(key, value);
100 | }
101 | }
102 |
103 | file.close();
104 | return true;
105 | }
106 |
107 | bool WorkspaceState::loadCommonState(QString *errorPath, int *errorCode)
108 | {
109 | QString filePath = recentCommonFilePath();
110 |
111 | QFile file(filePath);
112 | if (!file.exists()) {
113 | // File doesn't exist yet - not an error, just no state to load
114 | return true;
115 | }
116 |
117 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
118 | if (errorPath) *errorPath = filePath;
119 | if (errorCode) *errorCode = errno(*__errno_location ());
120 | return false;
121 | }
122 | file.close();
123 |
124 | // Clear existing state before loading
125 | QList<RecentFileInfo> newFileList;
126 |
127 | bool success = parseRecentFile(filePath, [&newFileList](const QString &key, const QString &value) {
128 | if (key == KEY_CAPTURE_FILE) {
129 | // Recent files are stored oldest first, newest last
130 | // We append to maintain that order
131 | if (!value.isEmpty()) {
132 | RecentFileInfo info;
133 | info.size = 0;
134 | info.accessible = false;
135 | info.filename = value;
136 | newFileList.append(info);
137 | }
138 | }
139 | // Future: handle other keys here
140 | // else if (key == KEY_DISPLAY_FILTER) { ... }
141 | });
142 |
143 | if (success) {
144 | recent_capture_files_.clear();
145 | recent_capture_files_.append(newFileList);
146 |
147 | // Queue async status checks for all loaded files
148 | for (const RecentFileInfo &info : newFileList) {
149 | queueFileStatusCheck(info.filename);
150 | }
151 |
152 | emit stateLoaded();
153 | }
154 |
155 | return success;
156 | }
157 |
158 | const QList<RecentFileInfo>& WorkspaceState::recentCaptureFiles() const
159 | {
160 | return recent_capture_files_;
161 | }
162 |
163 | QStringList WorkspaceState::recentCaptureFilenames() const
164 | {
165 | QStringList filenames;
166 |
167 | for (const RecentFileInfo &info : recent_capture_files_) {
168 | filenames.append(info.filename);
169 | }
170 | return filenames;
171 | }
172 |
173 | void WorkspaceState::addRecentCaptureFile(const QString &filePath)
174 | {
175 | if (filePath.isEmpty()) {
176 | return;
177 | }
178 |
179 | // Remove existing entry if present (Qt5-compatible approach)
180 | auto matchesPath = [&filePath](const RecentFileInfo &info) {
181 | return filePathsMatch(info.filename, filePath);
182 | };
183 | recent_capture_files_.erase(
184 | std::remove_if(recent_capture_files_.begin(), recent_capture_files_.end(), matchesPath),
185 | recent_capture_files_.end());
186 |
187 | // Add to end (newest last, matching the file format)
188 | RecentFileInfo info;
189 | info.size = 0;
190 | info.accessible = false;
191 | info.filename = filePath;
192 | recent_capture_files_.append(info);
193 |
194 | // Trim to max size (remove oldest = front of list)
195 | int maxRecentFiles = static_cast<int>(prefs.gui_recent_files_count_max);
196 | if (recent_capture_files_.size() > maxRecentFiles) {
197 | recent_capture_files_ = recent_capture_files_.mid(recent_capture_files_.size() - maxRecentFiles);
198 | }
199 |
200 | // Queue async status check for the newly added file
201 | queueFileStatusCheck(filePath);
202 |
203 | emit recentCaptureFilesChanged();
204 | write_recent(); // Persist immediately
205 | }
206 |
207 | void WorkspaceState::removeRecentCaptureFile(const QString &filePath)
208 | {
209 | // Qt5-compatible approach using std::remove_if
210 | auto matchesPath = [&filePath](const RecentFileInfo &info) {
211 | return filePathsMatch(info.filename, filePath);
212 | };
213 | auto originalSize = recent_capture_files_.size();
214 | auto newEnd = std::remove_if(recent_capture_files_.begin(), recent_capture_files_.end(), matchesPath);
215 | recent_capture_files_.erase(newEnd, recent_capture_files_.end());
216 |
217 | if (recent_capture_files_.size() < originalSize) {
218 | emit recentCaptureFilesChanged();
219 | write_recent(); // Persist immediately
220 | }
221 | }
222 |
223 | void WorkspaceState::clearRecentCaptureFiles()
224 | {
225 | if (!recent_capture_files_.isEmpty()) {
226 | recent_capture_files_.clear();
227 | emit recentCaptureFilesChanged();
228 | write_recent(); // Persist immediately
229 | }
230 | }
231 |
232 | void WorkspaceState::queueFileStatusCheck(const QString &filename)
233 | {
234 | // Force deep copy for thread safety
235 | QString filenameCopy = QString::fromStdU16String(filename.toStdU16String());
236 |
237 | QThreadPool::globalInstance()->start([this, filenameCopy]() {
238 | QFileInfo fileInfo(filenameCopy);
239 | qint64 size = 0;
240 | bool accessible = false;
241 |
242 | if (fileInfo.isFile() && fileInfo.isReadable()) {
1 | Assuming the condition is false | →
243 | size = fileInfo.size();
244 | accessible = true;
245 | }
246 |
247 | // Queue the result back to the main thread
248 | QMetaObject::invokeMethod(this, [this, filenameCopy, size, accessible]() {
2 | ← | Calling 'QMetaObject::invokeMethod' | →
249 | onFileStatusChecked(filenameCopy, size, accessible);
250 | }, Qt::QueuedConnection);
251 | });
252 | }
253 |
254 | void WorkspaceState::onFileStatusChecked(const QString &filename, qint64 size, bool accessible)
255 | {
256 | for (RecentFileInfo &info : recent_capture_files_) {
257 | if (filePathsMatch(info.filename, filename)) {
258 | if (info.size != size || info.accessible != accessible) {
259 | info.size = size;
260 | info.accessible = accessible;
261 | emit recentFileStatusChanged(filename);
262 | }
263 | break;
264 | }
265 | }
266 | }

←

#### /usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h

1 | // Copyright (C) 2022 The Qt Company Ltd.
2 | // Copyright (C) 2019 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 | #ifndef QOBJECTDEFS_H
6 | #define QOBJECTDEFS_H
7 |
8 | #if defined(__OBJC__) && !defined(__cplusplus201703L)
9 | # warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
10 | #endif
11 |
12 | #include <QtCore/qnamespace.h>
13 | #include <QtCore/qobjectdefs_impl.h>
14 | #include <QtCore/qtmetamacros.h>
15 |
16 | QT_BEGIN_NAMESPACE
17 |
18 | class QByteArray;
19 | struct QArrayData;
20 |
21 | class QString;
22 |
23 | #ifndef QT_NO_META_MACROS
24 | // macro for onaming members
25 | #ifdef METHOD
26 | #undef METHOD
27 | #endif
28 | #ifdef SLOT
29 | #undef SLOT
30 | #endif
31 | #ifdef SIGNAL
32 | #undef SIGNAL
33 | #endif
34 | #endif // QT_NO_META_MACROS
35 |
36 | Q_CORE_EXPORT__attribute__((visibility("default"))) const char *qFlagLocation(const char *method);
37 |
38 | #ifndef QT_NO_META_MACROS
39 | # define QMETHOD_CODE0 0 // member type codes
40 | # define QSLOT_CODE1 1
41 | # define QSIGNAL_CODE2 2
42 | # define QT_PREFIX_CODE(code, a)"code" "a" QT_STRINGIFY(code)"code" #a
43 | # define QT_STRINGIFY_METHOD(a)"0" "a" QT_PREFIX_CODE(QMETHOD_CODE, a)"0" "a"
44 | # define QT_STRINGIFY_SLOT(a)"1" "a" QT_PREFIX_CODE(QSLOT_CODE, a)"1" "a"
45 | # define QT_STRINGIFY_SIGNAL(a)"2" "a" QT_PREFIX_CODE(QSIGNAL_CODE, a)"2" "a"
46 | # ifndef QT_NO_DEBUG
47 | # define QLOCATION"\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "47" "\0" __FILE__"/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" QT_STRINGIFY(__LINE__)"47"
48 | # ifndef QT_NO_KEYWORDS
49 | # define METHOD(a)qFlagLocation("0" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "49") qFlagLocation(QT_STRINGIFY_METHOD(a)"0" "a" QLOCATION"\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "49")
50 | # endif
51 | # define SLOT(a)qFlagLocation("1" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "51") qFlagLocation(QT_STRINGIFY_SLOT(a)"1" "a" QLOCATION"\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "51")
52 | # define SIGNAL(a)qFlagLocation("2" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "52") qFlagLocation(QT_STRINGIFY_SIGNAL(a)"2" "a" QLOCATION"\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "52")
53 | # else
54 | # ifndef QT_NO_KEYWORDS
55 | # define METHOD(a)qFlagLocation("0" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "55") QT_STRINGIFY_METHOD(a)"0" "a"
56 | # endif
57 | # define SLOT(a)qFlagLocation("1" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "57") QT_STRINGIFY_SLOT(a)"1" "a"
58 | # define SIGNAL(a)qFlagLocation("2" "a" "\0" "/usr/include/x86_64-linux-gnu/qt6/QtCore/qobjectdefs.h" ":" "58") QT_STRINGIFY_SIGNAL(a)"2" "a"
59 | # endif
60 | #endif // QT_NO_META_MACROS
61 |
62 | #define Q_ARG(type, data)QArgument<type >("type", data) QArgument<type >(#type, data)
63 | #define Q_RETURN_ARG(type, data)QReturnArgument<type >("type", data) QReturnArgument<type >(#type, data)
64 |
65 | class QObject;
66 | class QMetaMethod;
67 | class QMetaEnum;
68 | class QMetaProperty;
69 | class QMetaClassInfo;
70 |
71 | namespace QtPrivate {
72 | class QMetaTypeInterface;
73 | }
74 |
75 | struct QMethodRawArguments
76 | {
77 | void **arguments;
78 | };
79 |
80 | class Q_CORE_EXPORT__attribute__((visibility("default"))) QGenericArgument
81 | {
82 | public:
83 | inline QGenericArgument(const char *aName = nullptr, const void *aData = nullptr)
84 | : _data(aData), _name(aName) {}
85 | inline void *data() const { return const_cast<void *>(_data); }
86 | inline const char *name() const { return _name; }
87 |
88 | private:
89 | const void *_data;
90 | const char *_name;
91 | };
92 |
93 | class Q_CORE_EXPORT__attribute__((visibility("default"))) QGenericReturnArgument: public QGenericArgument
94 | {
95 | public:
96 | inline QGenericReturnArgument(const char *aName = nullptr, void *aData = nullptr)
97 | : QGenericArgument(aName, aData)
98 | {}
99 | };
100 |
101 | template <class T>
102 | class QArgument: public QGenericArgument
103 | {
104 | public:
105 | inline QArgument(const char *aName, const T &aData)
106 | : QGenericArgument(aName, static_cast<const void *>(&aData))
107 | {}
108 | };
109 | template <class T>
110 | class QArgument<T &>: public QGenericArgument
111 | {
112 | public:
113 | inline QArgument(const char *aName, T &aData)
114 | : QGenericArgument(aName, static_cast<const void *>(&aData))
115 | {}
116 | };
117 |
118 |
119 | template <typename T>
120 | class QReturnArgument: public QGenericReturnArgument
121 | {
122 | public:
123 | inline QReturnArgument(const char *aName, T &aData)
124 | : QGenericReturnArgument(aName, static_cast<void *>(&aData))
125 | {}
126 | };
127 |
128 | struct Q_CORE_EXPORT__attribute__((visibility("default"))) QMetaObject
129 | {
130 | class Connection;
131 | const char *className() const;
132 | const QMetaObject *superClass() const;
133 |
134 | bool inherits(const QMetaObject *metaObject) const noexcept;
135 | QObject *cast(QObject *obj) const
136 | { return const_cast<QObject *>(cast(const_cast<const QObject *>(obj))); }
137 | const QObject *cast(const QObject *obj) const;
138 |
139 | #if !defined(QT_NO_TRANSLATION) || defined(Q_CLANG_QDOC)
140 | QString tr(const char *s, const char *c, int n = -1) const;
141 | #endif // QT_NO_TRANSLATION
142 |
143 | QMetaType metaType() const;
144 |
145 | int methodOffset() const;
146 | int enumeratorOffset() const;
147 | int propertyOffset() const;
148 | int classInfoOffset() const;
149 |
150 | int constructorCount() const;
151 | int methodCount() const;
152 | int enumeratorCount() const;
153 | int propertyCount() const;
154 | int classInfoCount() const;
155 |
156 | int indexOfConstructor(const char *constructor) const;
157 | int indexOfMethod(const char *method) const;
158 | int indexOfSignal(const char *signal) const;
159 | int indexOfSlot(const char *slot) const;
160 | int indexOfEnumerator(const char *name) const;
161 | int indexOfProperty(const char *name) const;
162 | int indexOfClassInfo(const char *name) const;
163 |
164 | QMetaMethod constructor(int index) const;
165 | QMetaMethod method(int index) const;
166 | QMetaEnum enumerator(int index) const;
167 | QMetaProperty property(int index) const;
168 | QMetaClassInfo classInfo(int index) const;
169 | QMetaProperty userProperty() const;
170 |
171 | static bool checkConnectArgs(const char *signal, const char *method);
172 | static bool checkConnectArgs(const QMetaMethod &signal,
173 | const QMetaMethod &method);
174 | static QByteArray normalizedSignature(const char *method);
175 | static QByteArray normalizedType(const char *type);
176 |
177 | // internal index-based connect
178 | static Connection connect(const QObject *sender, int signal_index,
179 | const QObject *receiver, int method_index,
180 | int type = 0, int *types = nullptr);
181 | // internal index-based disconnect
182 | static bool disconnect(const QObject *sender, int signal_index,
183 | const QObject *receiver, int method_index);
184 | static bool disconnectOne(const QObject *sender, int signal_index,
185 | const QObject *receiver, int method_index);
186 | // internal slot-name based connect
187 | static void connectSlotsByName(QObject *o);
188 |
189 | // internal index-based signal activation
190 | static void activate(QObject *sender, int signal_index, void **argv);
191 | static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
192 | static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
193 |
194 | static bool invokeMethod(QObject *obj, const char *member,
195 | Qt::ConnectionType,
196 | QGenericReturnArgument ret,
197 | QGenericArgument val0 = QGenericArgument(nullptr),
198 | QGenericArgument val1 = QGenericArgument(),
199 | QGenericArgument val2 = QGenericArgument(),
200 | QGenericArgument val3 = QGenericArgument(),
201 | QGenericArgument val4 = QGenericArgument(),
202 | QGenericArgument val5 = QGenericArgument(),
203 | QGenericArgument val6 = QGenericArgument(),
204 | QGenericArgument val7 = QGenericArgument(),
205 | QGenericArgument val8 = QGenericArgument(),
206 | QGenericArgument val9 = QGenericArgument());
207 |
208 | static inline bool invokeMethod(QObject *obj, const char *member,
209 | QGenericReturnArgument ret,
210 | QGenericArgument val0 = QGenericArgument(nullptr),
211 | QGenericArgument val1 = QGenericArgument(),
212 | QGenericArgument val2 = QGenericArgument(),
213 | QGenericArgument val3 = QGenericArgument(),
214 | QGenericArgument val4 = QGenericArgument(),
215 | QGenericArgument val5 = QGenericArgument(),
216 | QGenericArgument val6 = QGenericArgument(),
217 | QGenericArgument val7 = QGenericArgument(),
218 | QGenericArgument val8 = QGenericArgument(),
219 | QGenericArgument val9 = QGenericArgument())
220 | {
221 | return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
222 | val4, val5, val6, val7, val8, val9);
223 | }
224 |
225 | static inline bool invokeMethod(QObject *obj, const char *member,
226 | Qt::ConnectionType type,
227 | QGenericArgument val0 = QGenericArgument(nullptr),
228 | QGenericArgument val1 = QGenericArgument(),
229 | QGenericArgument val2 = QGenericArgument(),
230 | QGenericArgument val3 = QGenericArgument(),
231 | QGenericArgument val4 = QGenericArgument(),
232 | QGenericArgument val5 = QGenericArgument(),
233 | QGenericArgument val6 = QGenericArgument(),
234 | QGenericArgument val7 = QGenericArgument(),
235 | QGenericArgument val8 = QGenericArgument(),
236 | QGenericArgument val9 = QGenericArgument())
237 | {
238 | return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
239 | val3, val4, val5, val6, val7, val8, val9);
240 | }
241 |
242 | static inline bool invokeMethod(QObject *obj, const char *member,
243 | QGenericArgument val0 = QGenericArgument(nullptr),
244 | QGenericArgument val1 = QGenericArgument(),
245 | QGenericArgument val2 = QGenericArgument(),
246 | QGenericArgument val3 = QGenericArgument(),
247 | QGenericArgument val4 = QGenericArgument(),
248 | QGenericArgument val5 = QGenericArgument(),
249 | QGenericArgument val6 = QGenericArgument(),
250 | QGenericArgument val7 = QGenericArgument(),
251 | QGenericArgument val8 = QGenericArgument(),
252 | QGenericArgument val9 = QGenericArgument())
253 | {
254 | return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
255 | val1, val2, val3, val4, val5, val6, val7, val8, val9);
256 | }
257 |
258 | #ifdef Q_CLANG_QDOC
259 | template<typename Functor, typename FunctorReturnType>
260 | static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
261 | template<typename Functor, typename FunctorReturnType>
262 | static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret);
263 | #else
264 |
265 | // invokeMethod() for member function pointer
266 | template <typename Func>
267 | static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
268 | && !std::is_convertible<Func, const char*>::value
269 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
270 | invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
271 | Func function,
272 | Qt::ConnectionType type = Qt::AutoConnection,
273 | typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
274 | {
275 | return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);
276 | }
277 |
278 | template <typename Func>
279 | static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
280 | && !std::is_convertible<Func, const char*>::value
281 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
282 | invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
283 | Func function,
284 | typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
285 | {
286 | return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), Qt::AutoConnection, ret);
287 | }
288 |
289 | // invokeMethod() for function pointer (not member)
290 | template <typename Func>
291 | static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
292 | && !std::is_convertible<Func, const char*>::value
293 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
294 | invokeMethod(QObject *context, Func function,
295 | Qt::ConnectionType type = Qt::AutoConnection,
296 | typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
297 | {
298 | return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), type, ret);
299 | }
300 |
301 | template <typename Func>
302 | static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
303 | && !std::is_convertible<Func, const char*>::value
304 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
305 | invokeMethod(QObject *context, Func function,
306 | typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
307 | {
308 | return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), Qt::AutoConnection, ret);
309 | }
310 |
311 | // invokeMethod() for Functor
312 | template <typename Func>
313 | static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
314 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
315 | && !std::is_convertible<Func, const char*>::value, bool>::type
316 | invokeMethod(QObject *context, Func function,
317 | Qt::ConnectionType type = Qt::AutoConnection, decltype(function()) *ret = nullptr)
318 | {
319 | return invokeMethodImpl(context,
4 | ← | Potential memory leak
320 | new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(std::move(function)),
3 | ← | Memory is allocated | →
321 | type,
322 | ret);
323 | }
324 |
325 | template <typename Func>
326 | static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
327 | && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
328 | && !std::is_convertible<Func, const char*>::value, bool>::type
329 | invokeMethod(QObject *context, Func function, decltype(function()) *ret)
330 | {
331 | return invokeMethodImpl(context,
332 | new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(std::move(function)),
333 | Qt::AutoConnection,
334 | ret);
335 | }
336 |
337 | #endif
338 |
339 | QObject *newInstance(QGenericArgument val0 = QGenericArgument(nullptr),
340 | QGenericArgument val1 = QGenericArgument(),
341 | QGenericArgument val2 = QGenericArgument(),
342 | QGenericArgument val3 = QGenericArgument(),
343 | QGenericArgument val4 = QGenericArgument(),
344 | QGenericArgument val5 = QGenericArgument(),
345 | QGenericArgument val6 = QGenericArgument(),
346 | QGenericArgument val7 = QGenericArgument(),
347 | QGenericArgument val8 = QGenericArgument(),
348 | QGenericArgument val9 = QGenericArgument()) const;
349 |
350 | enum Call {
351 | InvokeMetaMethod,
352 | ReadProperty,
353 | WriteProperty,
354 | ResetProperty,
355 | CreateInstance,
356 | IndexOfMethod,
357 | RegisterPropertyMetaType,
358 | RegisterMethodArgumentMetaType,
359 | BindableProperty,
360 | CustomCall
361 | };
362 |
363 | int static_metacall(Call, int, void **) const;
364 | static int metacall(QObject *, Call, int, void **);
365 |
366 | template <const QMetaObject &MO> static constexpr const QMetaObject *staticMetaObject()
367 | {
368 | return &MO;
369 | }
370 |
371 | struct SuperData {
372 | using Getter = const QMetaObject *(*)();
373 | const QMetaObject *direct;
374 | SuperData() = default;
375 | constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
376 | constexpr SuperData(const QMetaObject *mo) : direct(mo) {}
377 |
378 | constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
379 |
380 | #ifdef QT_NO_DATA_RELOCATION
381 | Getter indirect = nullptr;
382 | constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
383 | constexpr operator const QMetaObject *() const
384 | { return indirect ? indirect() : direct; }
385 | template <const QMetaObject &MO> static constexpr SuperData link()
386 | { return SuperData(QMetaObject::staticMetaObject<MO>); }
387 | #else
388 | constexpr SuperData(Getter g) : direct(g()) {}
389 | constexpr operator const QMetaObject *() const
390 | { return direct; }
391 | template <const QMetaObject &MO> static constexpr SuperData link()
392 | { return SuperData(QMetaObject::staticMetaObject<MO>()); }
393 | #endif
394 | };
395 |
396 | struct Data { // private data
397 | SuperData superdata;
398 | const uint *stringdata;
399 | const uint *data;
400 | typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
401 | StaticMetacallFunction static_metacall;
402 | const SuperData *relatedMetaObjects;
403 | const QtPrivate::QMetaTypeInterface *const *metaTypes;
404 | void *extradata; //reserved for future use
405 | } d;
406 |
407 | private:
408 | static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
409 | friend class QTimer;
410 | };
411 |
412 | class Q_CORE_EXPORT__attribute__((visibility("default"))) QMetaObject::Connection {
413 | void *d_ptr; //QObjectPrivate::Connection*
414 | explicit Connection(void *data) : d_ptr(data) { }
415 | friend class QObject;
416 | friend class QObjectPrivate;
417 | friend struct QMetaObject;
418 | bool isConnected_helper() const;
419 | public:
420 | ~Connection();
421 | Connection();
422 | Connection(const Connection &other);
423 | Connection &operator=(const Connection &other);
424 | #ifdef Q_QDOC
425 | operator bool() const;
426 | #else
427 | // still using the restricted bool trick here, in order to support
428 | // code using copy-init (e.g. `bool ok = connect(...)`)
429 | typedef void *Connection::*RestrictedBool;
430 | operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; }
431 | #endif
432 |
433 | Connection(Connection &&other) noexcept : d_ptr(qExchange(other.d_ptr, nullptr)) {}
434 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Connection)Connection &operator=(Connection &&other) noexcept { swap(other); return *this; }
435 | void swap(Connection &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
436 | };
437 |
438 | inline void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept
439 | {
440 | lhs.swap(rhs);
441 | }
442 |
443 | inline const QMetaObject *QMetaObject::superClass() const
444 | { return d.superdata; }
445 |
446 | namespace QtPrivate {
447 | /* Trait that tells is a the Object has a Q_OBJECT macro */
448 | template <typename Object> struct HasQ_OBJECT_Macro {
449 | template <typename T>
450 | static char test(int (T::*)(QMetaObject::Call, int, void **));
451 | static int test(int (Object::*)(QMetaObject::Call, int, void **));
452 | enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
453 | };
454 | }
455 |
456 | QT_END_NAMESPACE
457 |
458 | #endif // QOBJECTDEFS_H