Creating a SSL socket in Qt for Android
-
@jsulm yes I have found it in
/opt/Qt5.15/include/QtSerialPort
And yes I went to Projects > Build > CMake > Build directory and entered a new directory. -
@diego-qt Strange thing is that compiler does not complain about QSslSocket include. Check the QSslSocket header file to see whether it declares the QSslSocket class.
-
@jsulm hi, I'm back after some time, still with the QSslSocket problem, any help is much appreciated
I looked into the QSslSocket header file and it contains only this:
#include "qsslsocket.h"
And the so called
qsslsocket.h
does exist@diego-qt said in Creating a SSL socket in Qt for Android:
And the so called qsslsocket.h does exist
And does it define the QSslSocket class?
-
@diego-qt said in Creating a SSL socket in Qt for Android:
And the so called qsslsocket.h does exist
And does it define the QSslSocket class?
-
@jsulm yes indeed, the class definition starts with
class Q_NETWORK_EXPORT QSslSocket : public QTcpSocket {
-
I see that my problem is Android-related, because when I try to compile the same project with my Desktop kit, it works.
QSslSocket
is recognized. -
@diego-qt Could be that QSslSocket is not available on Android. Look for #ifdef/#ifndef in the header file.
@jsulm I see something interesting now that you mention it.
#ifndef QT_NO_SSL
When I activate the Android kit, the code under this
#ifndef
directive is grayed out (so most of the code, actually). I'm guessing I have to activate it, but putting#ifndef QT_NO_SSL #define QT_NO_SSL #endif
in my header file before calling
#include <QSslSocket>
does not do the trick. How could it be done ?By the way, I see that when I activate the Desktop kit, the definition of QSslSocket in
qsslsocket.h
is not grayed out. -
These bug reports suggest that I'm not the only one with this problem:
https://bugreports.qt.io/browse/QTBUG-88238
https://bugreports.qt.io/browse/QTBUG-65531But there haven't been answers on the issues.
-
@jsulm I found that the
qsslsocket.h
file starts with:#include <QtNetwork/qtnetworkglobal.h> #include <QtCore/qlist.h> #include <QtCore/qregexp.h> #include <QtCore/qvector.h>
And the
QtNetwork/qtnetworkglobal.h
file starts with:#include <QtCore/qglobal.h> #include <QtNetwork/qtnetwork-config.h>
And finally, in the
QtNetwork/qtnetwork-config.h
file I found (among other defines):#define QT_NO_SSL
I have the impression then that QSslSocket can't be defined when in Android kit. However, when I activate the Desktop kit, the
#define QT_NO_SSL
is not found in the last file I mentioned, that's why my project compiles with this kit.
I don't understand why this happens. I might need to rerun a configuration file but I don't know what exactly to do. -
Hello @jsulm I have looked deeper into my problem and found some things. Could you help me by confirming as far as you can? Or recommend someone that may know the answer?
I found a new documentation page I hadn't read: https://doc.qt.io/qt-5/ssl.html#enabling-and-disabling-ssl-support
When I launched the configure program with theopenssl-linked
option, I finally got aQtNetwork/qtnetwork-config.h
file without the definition that caused trouble (see above). However, when I tried to save the newqmake
version and its Android kit, I get an error saying that the Android Clang compiler "can't produce code for the Qt version "Qt 5.15.13 (Qt-5.15.13)" (x86-linux-generic-elf-64bit)."What I understand is that I didn't activate the target for cross-compilation in the initial configuration step.
So I went back and launched thisOPENSSL_LIBS='-L~/android-sdk/android_openssl/ssl_1.1/arm64-v8a/include -lssl -lcrypto' \ ~/qt5/configure -openssl-linked -prefix /opt/Qt5.15 -xplatform android-clang \ -disable-rpath -nomake tests -nomake examples -android-ndk ~/android-sdk/ndk/21.3.6528147 \ -android-sdk ~/android-sdk -no-warnings-are-errors -opensource -confirm-license
But I got the following error:
ERROR: Feature 'openssl-linked' was enabled, but the pre-condition '!features.securetransport && !features.schannel && libs.openssl' failed. Check config.log for details.
Please note that when I launch the mentioned command without
-xplatform android-clang
, it seems to work and I am asked to launchgmake
. So for the time being I have found myself in an incompatibility of installing an SSL-supported Qt and cross-compiling for Android.Regarding the config log file that the error indicates me, I don't know what exactly to look at.
What I find interesting is that at some point there is this SSL-related error (with the -xplatform option):+ cd /home/diego/qt-build/config.tests/openssl && MAKEFLAGS= /usr/bin/gmake clean && MAKEFLAGS= /usr/bin/gmake > rm -rf /home/diego/qt-build/config.tests/openssl/android-build > rm -f main.o > rm -f *~ core *.core > /home/diego/android-sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -c -target aarch64-linux-android21 -fno-limit-debug-info -fPIC -fstack-protector-strong -DANDROID -O2 -fPIC -I. -I/home/diego/qt5/qtbase/mkspecs/android-clang -o main.o main.cpp > main.cpp:2:10: fatal error: 'openssl/ssl.h' file not found > #include <openssl/ssl.h> > ^~~~~~~~~~~~~~~ > 1 error generated. > gmake: *** [Makefile:193 : main.o] Erreur 1
The weird thing is that without the -xplatform option, I don't see this error, and yet the two command lines are otherwise the same one.
Apart from that, there are many other errors, but as I said I don't know exactly what to look at.