Category Archives: Platforms and frameworks

QT app is deactivated incorrectly on Android 10 in Gesture mode

If I enable Gesture mode on an Android 10 emulator by tapping System->Gestures->System Navigation->Gesture Navigation and then deactivate my app by swiping and reactivate it back, I get the following in the log:

adb logcat | grep "\ Lines"
05-04 21:52:36.389 11794 11939 D Lines   : Squircle::aboutToQuit()
05-04 21:52:36.389 11794 11939 D Lines   : InterstitialAdWrapper clear() called.
05-04 21:52:36.392 11794 11939 D Lines   : InterstitialAdWrapper InterstitialAd destructor called.
05-04 21:52:36.393 11794 11939 D Lines   : Squircle destructor called.
05-04 21:52:36.396 11794 11939 W Lines   : exit app 0
...
05-04 21:52:37.032 11794 11939 D Lines   : OslSoundPool destructor
05-04 21:52:37.117  2040  2134 W InputDispatcher: channel '8474831 net.geographx.LinesGame/net.geographx.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
05-04 21:52:37.117  2040  2134 E InputDispatcher: channel '8474831 net.geographx.LinesGame/net.geographx.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-04 21:52:37.123  2040  3120 I WindowManager: WIN DEATH: Window{8474831 u0 net.geographx.LinesGame/net.geographx.MainActivity}
05-04 21:52:37.123  2040  3120 W InputDispatcher: Attempted to unregister already unregistered input channel '8474831 net.geographx.LinesGame/net.geographx.MainActivity (server)'
05-04 21:52:37.136  2040  3120 W ActivityManager: Scheduling restart of crashed service net.geographx.LinesGame/org.chromium.content.app.SandboxedProcessService0 in 1000ms
05-04 21:52:37.151  2040  2057 I ActivityManager: Process net.geographx.LinesGame (pid 11794) has died: cch CRE
05-04 21:52:38.034  2040  2057 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=net.geographx.LinesGame/net.geographx.MainActivity bnds=[37,882][238,1191]} from uid 10090
05-04 21:52:38.055  2040  2057 I chatty  : uid=1000(system) Binder:2040_2 identical 8 lines
05-04 21:52:38.099  2040  2072 I ActivityManager: Start proc 12702:net.geographx.LinesGame/u0a134 for activity {net.geographx.LinesGame/net.geographx.MainActivity}
05-04 21:52:38.101 12702 12702 W raphx.LinesGam: Unexpected CPU variant for X86 using defaults: x86
05-04 21:52:38.124 12702 12702 E raphx.LinesGam: Not starting debugger since process cannot load the jdwp agent.
...
05-04 21:52:38.966  2040  2069 I ActivityTaskManager: Displayed net.geographx.LinesGame/net.geographx.MainActivity: +931ms
05-04 21:52:39.062 12702 12826 D libLinesGameQt_x86.so: Translation file has been loaded successfully:  "LinesGame_en"
05-04 21:52:39.062 12702 12826 D Lines   : App version:  "2.5.11, #133"
05-04 21:52:39.072 12702 12826 D Lines   : QT/SysInfo: Device Pixel Ratio: 3  Screen DPI:  147.131
05-04 21:52:39.106 12702 12826 D Lines   : InterstitialAdWrapper  valid
05-04 21:52:39.185 12702 12826 D Lines   : qml: Registering adfree
05-04 21:52:39.189  7632  9145 W Finsky  : [672] gcs.d(23): net.geographx.LinesGame: No account found.
05-04 21:52:39.411 12702 12826 D Lines   : qml: adfree Component.onCompleted
05-04 21:52:39.413 12702 12826 D Lines   : InterstitialAdWrapper: calling Java method ' initializeInterstitialAd ' from C++
05-04 21:52:39.413 12702 12826 D Lines   : Starting the application event loop...
05-04 21:52:39.463 12702 12826 D Lines   : onApplicationStateChanged(Qt::ApplicationActive)
(more…)

Packaging QT application into Android App Bundle (AAB)

In Qt Creator 4.11.0 on Projects page check “Build .aab”:

This will create .aab file.

(more…)

My Android QT app crashes at qt_qFindChild_helper.

I have an Android QT app with more than has 14K active users at the moment of writing this post. The app is relatively stable, its crash rate is 0.34%:

(more…)

Adding interstitial ads to a QT application on Android platform

I keep working on my Lines Game and probably I try to make it the best Lines Game in the world, but there is some disappointing incident that prevents it from being the best and makes it a usual game that glitches a bit. To see the glitch in action download the beta version of the game.

Adding Interstitial Ads to a QT application on Android platform is an interesting and relatively exciting job. I learned the following facts while doing it:

  1. To build my app with Google Play Services I add com.google.android.gms:play-services-ads:18.1.1 dependency to build.gradle and add com.google.android.gms.version and com.google.android.gms.ads.APPLICATION_ID to the manifest.
  2. I do not specify additional permissions (uses-permission attributes INTERNET, WRITE_EXTERNAL_STORAGE, ACCESS_NETWORK_STATE) required by ads, but they are detected automatically when I upload the app to Google Play store and the used is not prompted to allow them when the app starts.
  3. QT main thread (on which QML UI is run) is not Android UI thread. So I cannot call Java advertising API from QML or C++ directly, but all the calls should be queued with runOnUiThread method.
  4. To access Context required by Java advertising API I replace QtActivity with my own custom activity that implements all the advertising logic and forwards all the lifecycle events to original QtActivity.
  5. When the interstitial ad is open my activity is paused and stopped (onPaused / onStopped event handlers are called in Java and onApplicationStateChanged with Qt::ApplicationInactive / Qt::ApplicationSuspended respectively ) and when the interstitial ad is closed my activity is resumed but in different ways either with onRestart.
(more…)

Compiling OpenSSL 1.1 with MSVC2017 for using with QT 5.13

QT does not work with OpenSSL 1.0 anymore. Versions QT 5.12.4 and above require OpenSSL 1.1, but fortunately OpenSSL 1.1 can be easily compiled with MS2017 as follows:

set PATH=%PATH%;C:\Perl64\bin
set PATH=%PATH%;C:\PFiles\nasm-2.14.02-win64
perl Configure VC-WIN64A
nmake

The key to the success is using ‘VS2017 x64 Native Tools Command Prompt‘, but not ‘VS2017 Developer Command Prompt’.

To make QT use OpenSSL, two dlls

libcrypto-1_1-x64.dll
libssl-1_1-x64.dll

should be copied to QT binary directory, for example, C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\bin

Determining .NET Framework version from the native C++ code.

.NET Framework version 4.5 and higher can be determined with the following C++ code:

#include <windows.h>

bool IsDotNet45Installed()
{
    DWORD value{};
    DWORD dataSize = sizeof(value);
        
    const LONG retCode = ::RegGetValue(
        HKEY_LOCAL_MACHINE,
        L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\",
        L"Release",
        RRF_RT_REG_DWORD,
        nullptr,
        &value,
        &dataSize
    );

    if (retCode != ERROR_SUCCESS)
    {
        return false;
    }

    return value >= 378389;
}
(more…)

How I built QT 5.11.1 for Android on Windows

I tried to build QT 5.11.1 for Android on Windows, and “configure.bat” completed successfully, but “mingw32-make” failed with with the following error:

No rule to make target 'vulkan/qvulkanfunctions_p.h', needed by '.obj\qvulkaninstance.obj'.

It is the bug fixed in QT 5.11.2 that is planned on August/September 2018.

When I build the master branch and copied the following files from it to \qtbase\src\gui\vulkan manually:

qvulkanfunctions.h
qvulkanfunctions_p.cpp
qvulkanfunctions_p.h

and started “mingw32-make” again I got another error:

(more…)

How I compiled OpenSSL from sources with VS2015

I installed Perl, downloaded and extracted OpenSSL 1.1.0h and built 64 bit version in VS2015 x64 Native Tools Command Prompt with the following commands:

set PATH=%PATH%;C:\Perl64\bin
perl Configure VC-WIN64A no-asm
nmake

32 bit version can be built with VC-WIN32 configuration option as described in INSTALL:

on Windows (only pick one of the targets for configuration):
$ perl Configure { VC-WIN32 | VC-WIN64A | VC-WIN64I | VC-CE }
$ nmake
$ nmake test
$ nmake install

probably ‘A’ suffix means AMD and ‘I’ means something else, so we need ‘A’.

(more…)

Regular expressions for editing DEF-file (Windows Module-Definition file)

The following regular expression (find/replace pair) in Visual Studio format removes extra whitespace and @ symbol from a DEF-file:

^[ \t]+(\b(?<name>_\w+|[\w-[0-9_]]\w*)\b)[ \t]+@(?<index>\d+)(?=\r?$)
${name}\t${index}

and converts it to such a form when it can be imported to MS Excel and sorted by the function number, so you can manually add new functions by incrementing the last number.

To convert the file back the following find/replace pair can be used:

^(\b(?<name>_\w+|[\w-[0-9_]]\w*)\b)[ \t](?<index>\d+)(?=\r?$)
\t${name}\t\t@${index}

Setting up QT Creator 4.6.1 for Android development on Windows 10

First I installed Android Studio. When it started I set an option to create the application with Native C++ support and Android NDK was automatically installed to C:\Users\AppData\Local\Android\Sdk\ndk-bundle, also I added Android-19 API level and somehow CMake was installed to C:\Users\AppData\Local\Android\Sdk\cmake\3.6.4111459. Then in QT Creator I opened Tools->Options->Devices->Android and specified the following paths:

(more…)