I try to make it by checking screen.orientation
, like here: /a/14301832/4159530 but it returns true
even for the desktop Chrome browser:
#include <emscripten.h>
#include "widget.h"
EM_JS(bool, callMobileCheck, (), {
let check = false;
if (typeof screen.orientation !== "undefined") {
check = true;
}
return check;
})
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
bool result = callMobileCheck();
qDebug() << result;
}
Solution: /a/29509267/4159530
#include <emscripten.h>
#include "widget.h"
EM_JS(bool, isMobile, (), {
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);;
})
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
qDebug() << "isMobile:" << isMobile();
}
pro
QT += core gui widgets
CONFIG += c++17
INCLUDEPATH += "C:emsdkupstreamemscriptencachesysrootinclude"
SOURCES +=
main.cpp
widget.cpp
HEADERS +=
widget.h