Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
exampleqjsascontainer.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
6
7 class Cache : public QObject
8 {
11
12 public:
14 if (auto it = m_cache.constFind(key); it != m_cache.constEnd()) {
15 return *it; // impicit conversion
16 } else {
17 return QJSValue::UndefinedValue; // implicit conversion
18 }
19 }
20
22 }
23
[qjs-as-container]
QHash< QString, QString > m_cache
Q_INVOKABLE QJSValue lookup(const QString &key)
\inmodule QtCore
Definition qhash.h:818
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:1279
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1209
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
@ UndefinedValue
Definition qjsvalue.h:35
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QSet< QString >::iterator it
GLuint64 key
#define QML_ELEMENT
#define Q_OBJECT
#define Q_INVOKABLE