mirror of
https://gitlab.com/eql/lqml.git
synced 2026-01-24 13:30:45 -08:00
add convenience function 'qml:hex' for storing qint64 values in QML/JS
This commit is contained in:
parent
3d23e6d2f4
commit
eff04b90f2
5 changed files with 27 additions and 6 deletions
|
|
@ -7,7 +7,7 @@
|
|||
#include <QQuickView>
|
||||
#include <QDebug>
|
||||
|
||||
const char LQML::version[] = "23.9.1"; // September 2023
|
||||
const char LQML::version[] = "23.9.2"; // September 2023
|
||||
|
||||
extern "C" void ini_LQML(cl_object);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,16 @@ static QVariant toVariant(const QJSValue& value) {
|
|||
#else
|
||||
const int type = var.typeId();
|
||||
#endif
|
||||
if (type == QMetaType::Double) {
|
||||
// workaround for uint32, see '>>>0' in QML
|
||||
quint32 uint = var.toUInt();
|
||||
if (uint == var.toDouble()) {
|
||||
return QVariant(uint);
|
||||
if (type == QMetaType::QString) {
|
||||
QString s(var.toString());
|
||||
// numbers passed with '(qml:hex number)' to QML (and stored there as
|
||||
// strings) are automatically converted back to a number (qint64).
|
||||
if (s.startsWith("#x")) {
|
||||
bool ok;
|
||||
qint64 num = s.mid(2).toLongLong(&ok, 16);
|
||||
if (ok) {
|
||||
return QVariant(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return var;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue