[Interest] qt6: any QtAndroid::androidActivity replacement?

Alexander Dyagilev alervdvcw at gmail.com
Sat Sep 18 17:13:04 CEST 2021


For those who can be interested. Here is my current qt5androidcompat.h 
file to ease the support of both Qt5 and Qt6. Here you can find how to 
use new Qt6 API:

#pragma once

#include <QtGlobal>

#ifdef Q_OS_ANDROID

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

#include <QtAndroid>
#include <QAndroidJniObject>

using QtJniObject = QAndroidJniObject;

inline QtJniObject qtAndroidContext()
{
     auto result = QtAndroid::androidActivity();
     if (result.isValid())
         return result;
     return QtAndroid::androidService();
}

inline int qtAndroidSdkVersion()
{
     return QtAndroid::androidSdkVersion();
}

inline void qt5RunOnAndroidMainThread(const QtAndroid::Runnable &runnable)
{
     QtAndroid::runOnAndroidThread(runnable);
}

#else

#include <QCoreApplication>
#include <QJniObject>

using QtJniObject = QJniObject;

inline QtJniObject qtAndroidContext()
{
     return QJniObject(QCoreApplication::instance()
->nativeInterface<QNativeInterface::QAndroidApplication>()
                       ->context());
}

inline int qtAndroidSdkVersion()
{
     return QCoreApplication::instance()
->nativeInterface<QNativeInterface::QAndroidApplication>()
             ->sdkVersion();
}

inline void qt5RunOnAndroidMainThread(const std::function<void()> &runnable)
{
     QCoreApplication::instance()
->nativeInterface<QNativeInterface::QAndroidApplication>()
             ->runOnAndroidMainThread([runnable]() {runnable(); return 
QVariant();});
}

#endif // #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

#endif // ANDROID

On 9/18/2021 3:53 PM, Alexander Dyagilev wrote:
> Hello,
>
> I'm trying to port my Android application from Qt5 to Qt6. 
> Documentation seems to be very poorly organized. I can't find anywhere 
> a section about new Qt Android classes.
>
> Can someone please give me the link (if any)?
>


More information about the Interest mailing list