Memory access by address
I have a program to access the variables by their addresses and this is my code:
QHash <int,int*> hash;
qDebug()<<"t1="<<t1; //t1= 34
qDebug()<<"f="<<f; //f=7.94536e-43 !!!!!!
why this code is not working? and how can i fix that?
Actually the objective of this code is to indexing every variable with any type (int, float, structure, Boolean, .. ) by an integer number. Hashing is used to achieve this goal.
Thanks a lot
If i use QVariant like below:
@QHash <int,QVariant*> hash;
and i insert the same values into it, i encounter this error:
: error: C2664: 'QHash<Key,T>::insert' : cannot convert parameter 2 from 'int *' to 'QVariant *const &'
But if i use the previous code and retrieve the address as below:
everything will be OK.
Better to not use pointers to your variables for this. A QVariant will use the same amount of memory space as the variable it will point to. So, the QHash should have an <int, QVariant> not the pointer. Then add the variable to the QVariant via a constructor or other variant function and you should be able to convert any variable into that QHash. Even mix them if needed.
thanks for your reply But could you please make an example of your plan?
Jeroentje@home meant that you should follow koahnig's example
QHash<int, QVariant> hash;
float fInput= 1.2
float myFloat = hash.value(1).toFloat();