I have realized that QVariant does not offer functionality for long
and unsigned long
. It offers conversions to int
, unsigned int
, long long
and unsigned long long
.
我已经意识到QVariant不提供长时间和无符号的功能。它提供转换到int、unsigned int、long long和unsigned long long。
We can find in current Desktop architectures that long
and int
are equivalent, but they are not from a theoretical point of view.
在当前的桌面架构中,我们可以发现long和int是等价的,但它们不是从理论的角度来看的。
If I want to store a long
in a QVariant
I am obligated to convert first the value to long long
. I would like to know if there is any other way to overcome this.
如果我想要存储一长串的q变体,我有义务首先将值转换为long long。我想知道是否还有其他方法来克服这个问题。
Secondly, I am interested to know the better/simpler way to do it. I.e. using a simpler code, and avoiding the use of unnecessary space or instructions.
其次,我很想知道做这件事的更好/更简单的方法。即使用更简单的代码,避免使用不必要的空间或指令。
2 个解决方案
#1
1
If I want to store a long
in a QVariant
, I am obligated to convert first the value to long long
.
如果我想在一个QVariant中存储很长时间,我有义务首先将值转换为long long。
QVariant store (unsigned long int input) {
unsigned long long data = (unsigned long long) input;
QVariant qvariant( data );
return qvariant;
}
unsigned long int load (const QVariant& qvariant) {
bool ok;
unsigned long int data = (unsigned long) qvariant.toULongLong(&ok);
if (ok)
return data;
else
return NAN;
}
#2
1
This problem don't concern the design QVariant class. but it's the problem of long type.
这个问题与设计QVariant类无关。但这是长类型的问题。
The long type change but int (4) or long long (8) is the same in all LLP64/IL32P64 LP64/I32LP64 as wikipedia note.
长类型变化但int(4)或long long(8)在所有LLP64/IL32P64 LP64/I32LP64中都是相同的。
Intel Developer zone say :
英特尔发展区表示:
Suggestion: If it is important to you for integer types to have the same size on all Intel platforms, then consider replacing "long" by either "int" or "long long". The size of the "int" integer type is 4 bytes and the size of the "long long" integer type is 8 bytes for all the above combinations of operating system and architecture.
建议:如果在所有的Intel平台上对整数类型都有相同的大小很重要,那么考虑用“int”或“long long”替换“long”。“int”整数类型的大小为4字节,“long long”整数类型的大小为8字节,用于所有操作系统和体系结构的所有组合。
Good luck
/Mohamed
祝你好运/*
#1
1
If I want to store a long
in a QVariant
, I am obligated to convert first the value to long long
.
如果我想在一个QVariant中存储很长时间,我有义务首先将值转换为long long。
QVariant store (unsigned long int input) {
unsigned long long data = (unsigned long long) input;
QVariant qvariant( data );
return qvariant;
}
unsigned long int load (const QVariant& qvariant) {
bool ok;
unsigned long int data = (unsigned long) qvariant.toULongLong(&ok);
if (ok)
return data;
else
return NAN;
}
#2
1
This problem don't concern the design QVariant class. but it's the problem of long type.
这个问题与设计QVariant类无关。但这是长类型的问题。
The long type change but int (4) or long long (8) is the same in all LLP64/IL32P64 LP64/I32LP64 as wikipedia note.
长类型变化但int(4)或long long(8)在所有LLP64/IL32P64 LP64/I32LP64中都是相同的。
Intel Developer zone say :
英特尔发展区表示:
Suggestion: If it is important to you for integer types to have the same size on all Intel platforms, then consider replacing "long" by either "int" or "long long". The size of the "int" integer type is 4 bytes and the size of the "long long" integer type is 8 bytes for all the above combinations of operating system and architecture.
建议:如果在所有的Intel平台上对整数类型都有相同的大小很重要,那么考虑用“int”或“long long”替换“long”。“int”整数类型的大小为4字节,“long long”整数类型的大小为8字节,用于所有操作系统和体系结构的所有组合。
Good luck
/Mohamed
祝你好运/*