How to convert unsigned long int to QVariant

I realized that QVariant does not offer functionality for long and unsigned long . It offers int , unsigned int , long long and unsigned long long conversions.

In modern desktop architectures, we can find that long and int equivalent, but they are not from a theoretical point of view.

If I want to store long in QVariant , I must first convert the value to long long . I would like to know if there is another way to overcome this.

Secondly, I am interested to know a better / easier way to do this. That is, using simpler code and avoiding the use of extra space or instructions.

+6
source share
2 answers

If I want to store long in QVariant , I must first convert the value to 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; } 
+1
source

This issue does not apply to the QVariant class. but this is a long type problem.

A long type change, but int (4) or long long (8) is the same in all LLP64 / IL32P64 LP64 / I32LP64 as a wikipedia note.

Intel Game Zone :

Suggestion: If integer types of the same size are important to you on all Intel platforms, then consider replacing "long" with either "int" or "long long". The size of the integer type "int" is 4 bytes, and the size of the "long long" integer type is 8 bytes for all the above combinations of the operating system and architecture.

Good luck
/ Mohamed

+1
source

Source: https://habr.com/ru/post/970938/


All Articles