summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qassociativeiterable.h2
-rw-r--r--src/corelib/kernel/qcore_mac.mm32
-rw-r--r--src/corelib/kernel/qcore_mac_p.h17
-rw-r--r--src/corelib/kernel/qiterable.h6
-rw-r--r--src/corelib/kernel/qjniobject.cpp76
-rw-r--r--src/corelib/kernel/qmetaassociation.h6
-rw-r--r--src/corelib/kernel/qmetasequence.h61
-rw-r--r--src/corelib/kernel/qsequentialiterable.h3
-rw-r--r--src/corelib/kernel/qvariant.h10
9 files changed, 144 insertions, 69 deletions
diff --git a/src/corelib/kernel/qassociativeiterable.h b/src/corelib/kernel/qassociativeiterable.h
index 39f66d45fa0..4f9bbf67bfb 100644
--- a/src/corelib/kernel/qassociativeiterable.h
+++ b/src/corelib/kernel/qassociativeiterable.h
@@ -156,10 +156,12 @@ inline QVariantRef<QAssociativeIterator>::operator QVariant() const
if (!metaType.isValid())
return m_pointer->key();
+ return [&] {
QVariant v(metaType);
metaAssociation.mappedAtIterator(m_pointer->constIterator(),
metaType == QMetaType::fromType<QVariant>() ? &v : v.data());
return v;
+ }();
}
template<>
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm
index 687fc7e85fa..f5f1f4a8cb8 100644
--- a/src/corelib/kernel/qcore_mac.mm
+++ b/src/corelib/kernel/qcore_mac.mm
@@ -22,6 +22,10 @@
#include <spawn.h>
#include <qdebug.h>
+#include <qpoint.h>
+#include <qsize.h>
+#include <qrect.h>
+#include <qmargins.h>
#include "qendian.h"
#include "qhash.h"
@@ -222,6 +226,34 @@ QDebug operator<<(QDebug dbg, CFStringRef stringRef)
return dbg;
}
+QDebug operator<<(QDebug dbg, CGPoint point)
+{
+ dbg << QPointF::fromCGPoint(point);
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, CGSize size)
+{
+ dbg << QSizeF::fromCGSize(size);
+ return dbg;
+}
+
+QDebug operator<<(QDebug dbg, CGRect rect)
+{
+ dbg << QRectF::fromCGRect(rect);
+ return dbg;
+}
+
+#if defined(Q_OS_MACOS)
+QDebug operator<<(QDebug dbg, NSEdgeInsets insets)
+#else
+QDebug operator<<(QDebug dbg, UIEdgeInsets insets)
+#endif
+{
+ dbg << QMargins(insets.left, insets.top, insets.right, insets.bottom);
+ return dbg;
+}
+
// Prevents breaking the ODR in case we introduce support for more types
// later on, and lets the user override our default QDebug operators.
#define QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 2c4b4c02c55..1e57ee01e1d 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -78,6 +78,15 @@ kern_return_t IOObjectRelease(io_object_t object);
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
+struct CGPoint;
+struct CGSize;
+struct CGRect;
+#if defined(Q_OS_MACOS)
+struct NSEdgeInsets;
+#else
+struct UIEdgeInsets;
+#endif
+
// @compatibility_alias doesn't work with categories or their methods
#define QtExtras QT_MANGLE_NAMESPACE(QtExtras)
@@ -225,6 +234,14 @@ Q_AUTOTEST_EXPORT void qt_mac_ensureResponsible();
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool);
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QCFString &string);
+Q_CORE_EXPORT QDebug operator<<(QDebug, CGPoint);
+Q_CORE_EXPORT QDebug operator<<(QDebug, CGSize);
+Q_CORE_EXPORT QDebug operator<<(QDebug, CGRect);
+#if defined(Q_OS_MACOS)
+Q_CORE_EXPORT QDebug operator<<(QDebug, NSEdgeInsets);
+#else
+Q_CORE_EXPORT QDebug operator<<(QDebug, UIEdgeInsets);
+#endif
#endif
Q_CORE_EXPORT bool qt_apple_isApplicationExtension();
diff --git a/src/corelib/kernel/qiterable.h b/src/corelib/kernel/qiterable.h
index baab2897967..494cec73a3f 100644
--- a/src/corelib/kernel/qiterable.h
+++ b/src/corelib/kernel/qiterable.h
@@ -502,7 +502,10 @@ public:
if (m_metaContainer.hasSize())
return m_metaContainer.size(container);
- // ### Qt7: Return -1 here. We shouldn't second-guess the underlying container
+#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
+ // We shouldn't second-guess the underlying container, so we're not synthesizing a size.
+ return -1;
+#else
QtPrivate::warnSynthesizedAccess(
"size() called on an iterable without native size accessor. This is slow");
@@ -515,6 +518,7 @@ public:
m_metaContainer.destroyConstIterator(begin);
m_metaContainer.destroyConstIterator(end);
return size;
+#endif
}
void clear()
diff --git a/src/corelib/kernel/qjniobject.cpp b/src/corelib/kernel/qjniobject.cpp
index abef9fdd663..21bfe5af448 100644
--- a/src/corelib/kernel/qjniobject.cpp
+++ b/src/corelib/kernel/qjniobject.cpp
@@ -27,7 +27,8 @@ using namespace Qt::StringLiterals;
garbage-collected and providing access to most \c JNIEnv method calls
(member, static) and fields (setter, getter). It eliminates much
boiler-plate that would normally be needed, with direct JNI access, for
- every operation, including exception-handling.
+ every operation. Exceptions thrown by called Java methods are cleared by
+ default, but can since Qt 6.11 also be handled by the caller.
\note This API has been designed and tested for use with Android.
It has not been tested for other platforms.
@@ -129,12 +130,46 @@ using namespace Qt::StringLiterals;
Note that while the first template parameter specifies the return type of the Java
function, the method will still return a QJniObject.
- \section1 Handling Java Exception
+ \section1 Handling Java Exceptions
After calling Java functions that might throw exceptions, it is important
to check for, handle and clear out any exception before continuing. All
- QJniObject functions handle exceptions internally by reporting and clearing them,
- saving client code the need to handle exceptions.
+ QJniObject functions can handle exceptions internally by reporting and
+ clearing them. This includes JNI exceptions, for instance when trying to
+ call a method that doesn't exist, or with bad parameters; and exceptions
+ are thrown by the method as a way of reporting errors or returning failure
+ information.
+
+ From Qt 6.11 on, client code can opt in to handle exceptions explicitly in
+ each call. To do so, use \c{std::expected} from C++ 23 as the return type,
+ with the value type as the expected, and \c{jthrowable} as the error type.
+ For instance, trying to read a setting value via the
+ \c{android.provider.Settings.Secure} type might throw an exception if the
+ setting does not exist.
+
+ \code
+ Q_DECLARE_JNI_CLASS(SettingsSecure, "android/provider/Settings$Secure")
+ using namespace QtJniTypes;
+
+ QString enabledInputMethods()
+ {
+ ContentResolver resolver;
+ SettingsSecure settings;
+
+ auto defaultInputMethods = settings.callMethod<std::expected<QString, jthrowable>>(
+ "getString", resolver, u"enabled_input_methods"_s
+ );
+ if (defaultInputMethods)
+ return defaultInputMethods.value();
+ QStringList stackTrace = QJniEnvironment::stackTrace(defaultInputMethods.error());
+ }
+ \endcode
+
+ You can use any other type that behaves like \c{std::expected}, so handling
+ exceptions explicitly is possible without using C++23. The only
+ requirements are that the type declares three nested types \c{value_type},
+ \c{error_type}, and \c{unexpected_type}, can be constructed from the value
+ type, and from its \c{unexpected_type} holding a \c{jthrowable}.
\note The user must handle exceptions manually when doing JNI calls using \c JNIEnv directly.
It is unsafe to make other JNI calls when exceptions are pending. For more information, see
@@ -921,7 +956,10 @@ QByteArray QJniObject::className() const
jint size = myJavaString.callMethod<jint>("length");
\endcode
- The method signature is deduced at compile time from \c Ret and the types of \a args.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Ret can be a \c{std::expected}-compatible type that returns
+ a value, or \l{Handling Java Exceptions}{any Java exception thrown} by the
+ called method.
*/
/*!
@@ -952,7 +990,10 @@ QByteArray QJniObject::className() const
jint value = QJniObject::callStaticMethod<jint>("MyClass", "staticMethod");
\endcode
- The method signature is deduced at compile time from \c Ret and the types of \a args.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Ret can be a \c{std::expected}-compatible type that returns
+ a value, or \l{Handling Java Exceptions}{any Java exception thrown} by the
+ called method.
*/
/*!
@@ -1009,7 +1050,10 @@ QByteArray QJniObject::className() const
jdouble randNr = QJniObject::callStaticMethod<jdouble>(javaMathClass, "random");
\endcode
- The method signature is deduced at compile time from \c Ret and the types of \a args.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Ret can be a \c{std::expected}-compatible type that returns
+ a value, or \l{Handling Java Exceptions}{any Java exception thrown} by the
+ called method.
*/
/*!
@@ -1020,8 +1064,12 @@ QByteArray QJniObject::className() const
\c Ret (unless \c Ret is \c void). If \c Ret is a jobject type, then the returned value will
be a QJniObject.
- The method signature is deduced at compile time from \c Ret and the types of \a args.
- \c Klass needs to be a C++ type with a registered type mapping to a Java type.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Klass needs to be a C++ type with a registered type mapping
+ to a Java type. \c Ret can be a \c{std::expected}-compatible type that
+ returns a value, or \l{Handling Java Exceptions}{any Java exception thrown}
+ by the called method.
+
*/
/*!
@@ -1150,7 +1198,10 @@ QJniObject QJniObject::callStaticObjectMethod(jclass clazz, jmethodID methodId,
QJniObject myJavaString2 = myJavaString1.callObjectMethod<jstring>("toString");
\endcode
- The method signature is deduced at compile time from \c Ret and the types of \a args.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Ret can be a \c{std::expected}-compatible type that returns
+ a value, or \l{Handling Java Exceptions}{any Java exception thrown} by the
+ called method.
*/
/*!
@@ -1164,7 +1215,10 @@ QJniObject QJniObject::callStaticObjectMethod(jclass clazz, jmethodID methodId,
QJniObject string = QJniObject::callStaticObjectMethod<jstring>("CustomClass", "getClassName");
\endcode
- The method signature is deduced at compile time from \c Ret and the types of \a args.
+ The method signature is deduced at compile time from \c Ret and the types
+ of \a args. \c Ret can be a \c{std::expected}-compatible type that returns
+ a value, or \l{Handling Java Exceptions}{any Java exception thrown} by the
+ called method.
*/
/*!
diff --git a/src/corelib/kernel/qmetaassociation.h b/src/corelib/kernel/qmetaassociation.h
index 6d8de13e90a..d481ae91079 100644
--- a/src/corelib/kernel/qmetaassociation.h
+++ b/src/corelib/kernel/qmetaassociation.h
@@ -25,8 +25,8 @@ public:
using reference = QVariant::Reference<AssociativeIterator>;
using pointer = QVariant::Pointer<AssociativeIterator>;
- static constexpr bool canNoexceptAssignQVariant = false;
- static constexpr bool canNoexceptConvertToQVariant = false;
+ static constexpr bool CanNoexceptAssignQVariant = false;
+ static constexpr bool CanNoexceptConvertToQVariant = false;
AssociativeIterator(QIterator &&it) : QIterator(std::move(it)) {}
@@ -51,7 +51,7 @@ public:
using reference = QVariant::ConstReference<AssociativeConstIterator>;
using pointer = QVariant::ConstPointer<AssociativeConstIterator>;
- static constexpr bool canNoexceptConvertToQVariant = false;
+ static constexpr bool CanNoexceptConvertToQVariant = false;
AssociativeConstIterator(QConstIterator &&it) : QConstIterator(std::move(it)) {}
diff --git a/src/corelib/kernel/qmetasequence.h b/src/corelib/kernel/qmetasequence.h
index e9505054159..26156e7924f 100644
--- a/src/corelib/kernel/qmetasequence.h
+++ b/src/corelib/kernel/qmetasequence.h
@@ -24,8 +24,8 @@ public:
using reference = QVariant::Reference<SequentialIterator>;
using pointer = QVariant::Pointer<SequentialIterator>;
- static constexpr bool canNoexceptAssignQVariant = false;
- static constexpr bool canNoexceptConvertToQVariant = false;
+ static constexpr bool CanNoexceptAssignQVariant = false;
+ static constexpr bool CanNoexceptConvertToQVariant = false;
SequentialIterator(QIterator &&it) : QIterator(std::move(it)) {}
@@ -41,7 +41,7 @@ public:
using reference = QVariant::ConstReference<SequentialConstIterator>;
using pointer = QVariant::ConstPointer<SequentialConstIterator>;
- static constexpr bool canNoexceptConvertToQVariant = false;
+ static constexpr bool CanNoexceptConvertToQVariant = false;
SequentialConstIterator(QConstIterator &&it) : QConstIterator(std::move(it)) {}
@@ -184,13 +184,15 @@ public:
return;
}
- // ### Qt7: Drop this code. We shouldn't second-guess the underlying container
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ // We shouldn't second-guess the underlying container.
QtPrivate::warnSynthesizedAccess(
"at() called on an iterable without native indexed accessors. This is slow");
void *it = meta.constBegin(m_iterable.constPointer());
meta.advanceConstIterator(it, idx);
meta.valueAtConstIterator(it, dataPtr);
meta.destroyConstIterator(it);
+#endif
});
}
@@ -204,13 +206,15 @@ public:
return;
}
- // ### Qt7: Drop this code. We shouldn't second-guess the underlying container
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ // We shouldn't second-guess the underlying container
QtPrivate::warnSynthesizedAccess(
"set() called on an iterable without native indexed accessors. This is slow");
void *it = meta.begin(m_iterable.mutablePointer());
meta.advanceIterator(it, idx);
meta.setValueAtIterator(it, dataPtr);
meta.destroyIterator(it);
+#endif
}
void append(const QVariant &value)
@@ -248,55 +252,14 @@ public:
Unspecified, AtBegin, AtEnd
};
- QT_DEPRECATED_VERSION_X_6_11("Use append() or prepend() instead.")
void addValue(const QVariant &value, Position position = Unspecified)
- {
- const QMetaSequence meta = metaContainer();
- QtPrivate::QVariantTypeCoercer coercer;
- const void *valuePtr = coercer.coerce(value, meta.valueMetaType());
-
- switch (position) {
- case AtBegin:
- if (meta.canAddValueAtBegin())
- meta.addValueAtBegin(mutableIterable(), valuePtr);
- break;
- case AtEnd:
- if (meta.canAddValueAtEnd())
- meta.addValueAtEnd(mutableIterable(), valuePtr);
- break;
- case Unspecified:
- if (meta.canAddValue())
- meta.addValue(mutableIterable(), valuePtr);
- break;
- }
- }
+ Q_DECL_EQ_DELETE_X("Use append() or prepend() instead.");
- QT_DEPRECATED_VERSION_X_6_11("Use removeLast() or removeFirst() instead.")
void removeValue(Position position = Unspecified)
- {
- const QMetaSequence meta = metaContainer();
+ Q_DECL_EQ_DELETE_X("Use removeLast() or removeFirst() instead.");
- switch (position) {
- case AtBegin:
- if (meta.canRemoveValueAtBegin())
- meta.removeValueAtBegin(mutableIterable());
- break;
- case AtEnd:
- if (meta.canRemoveValueAtEnd())
- meta.removeValueAtEnd(mutableIterable());
- break;
- case Unspecified:
- if (meta.canRemoveValue())
- meta.removeValue(mutableIterable());
- break;
- }
- }
-
- QT_DEPRECATED_VERSION_X_6_11("Use QMetaSequence::valueMetaType() instead.")
QMetaType valueMetaType() const
- {
- return metaContainer().valueMetaType();
- }
+ Q_DECL_EQ_DELETE_X("Use QMetaSequence::valueMetaType() instead.");
QT_WARNING_POP
#endif // QT_DEPRECATED_SINCE(6, 11)
diff --git a/src/corelib/kernel/qsequentialiterable.h b/src/corelib/kernel/qsequentialiterable.h
index 92252cb19dd..76908bdae4b 100644
--- a/src/corelib/kernel/qsequentialiterable.h
+++ b/src/corelib/kernel/qsequentialiterable.h
@@ -142,10 +142,13 @@ inline QVariantRef<QSequentialIterator>::operator QVariant() const
if (m_pointer == nullptr)
return QVariant();
const QMetaType metaType(m_pointer->metaContainer().valueMetaType());
+
+ return [&] {
QVariant v(metaType);
void *dataPtr = metaType == QMetaType::fromType<QVariant>() ? &v : v.data();
m_pointer->metaContainer().valueAtIterator(m_pointer->constIterator(), dataPtr);
return v;
+ }();
}
template<>
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 82eec0693d6..19cd1fea7fb 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -263,7 +263,7 @@ public:
ConstReference &operator=(ConstReference &&value) = delete;
// To be specialized for each Referred
- operator QVariant() const noexcept(Referred::canNoexceptConvertToQVariant);
+ operator QVariant() const noexcept(Referred::CanNoexceptConvertToQVariant);
};
template<typename Referred>
@@ -288,18 +288,18 @@ public:
~Reference() = default;
Reference &operator=(const Reference &value)
- noexcept(Referred::canNoexceptAssignQVariant)
+ noexcept(Referred::CanNoexceptAssignQVariant)
{
return operator=(QVariant(value));
}
Reference &operator=(Reference &&value)
- noexcept(Referred::canNoexceptAssignQVariant)
+ noexcept(Referred::CanNoexceptAssignQVariant)
{
return operator=(QVariant(value));
}
- operator QVariant() const noexcept(Referred::canNoexceptConvertToQVariant)
+ operator QVariant() const noexcept(Referred::CanNoexceptConvertToQVariant)
{
return ConstReference(m_referred);
}
@@ -313,7 +313,7 @@ public:
}
// To be specialized for each Referred
- Reference &operator=(const QVariant &value) noexcept(Referred::canNoexceptAssignQVariant);
+ Reference &operator=(const QVariant &value) noexcept(Referred::CanNoexceptAssignQVariant);
};
template<typename Pointed>