QML 中的 64 位整数

编程入门 行业动态 更新时间:2024-10-25 12:20:09
本文介绍了QML 中的 64 位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 QML 中处理 64 位整数?我知道无用的 Javascript 无法正常处理它们,因为它对所有内容都使用双精度,如果我尝试在信号中使用它们,所有内容都会设置为 undefined.有没有解决的办法?也许我必须使用 QVariant 之类的?

How do I deal with 64 bit integers in QML? I know that useless Javascript can't handle them normally as it uses doubles for everything, and if I try to use them in a signal, everything gets set to undefined. Is there a way around this? Perhaps I have to use a QVariant or something?

推荐答案

创建你自己的 Integer64 类派生自 QObject 并给它你需要的函数,比如p>

Create your own Integer64 class derived from QObject and give it the functions you need, like

class Integer64 : public QObject { Q_OBJECT public: // ... Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) QString value() const; void setValue(QString value); Q_INVOKABLE void add(Integer64 * other); Q_INVOKABLE void subtract(Integer64 * other); Q_INVOKABLE void multiply(Integer64 * other); Q_INVOKABLE void divide(Integer64 * other); // ...

使用 value() 在 QML 中获取字符串表示形式,使用 setValue() 从字符串表示形式中设置值.

where you use value() to get a string representation in QML and setValue() to set a value from a string representation.

可以使用额外的构造函数从 C++ 高效地创建 Integer64

An additional constructor can be used to efficiently create Integer64 from C++

public: explicit Integer64(QObject *parent = 0); explicit Integer64(qint64 value, QObject *parent); // ...

然后将类型注册到QML

Then register the type to QML

qmlRegisterType<Integer64>("MyModules", 1, 0, "Integer64");

更多推荐

QML 中的 64 位整数

本文发布于:2023-11-30 05:39:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   QML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!