我尝试通过检查
screen.orientation
来实现它,如下所示:https://stackoverflow.com/a/14301832/4159530,但即使对于桌面 Chrome 浏览器,它也会返回 true
:
#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;
}
解决方案:https://stackoverflow.com/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();
}
亲
QT += core gui widgets
CONFIG += c++17
INCLUDEPATH += "C:\emsdk\upstream\emscripten\cache\sysroot\include"
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h