Now i have solved the problem with a handler:
// global variable
double xy; // could be any other type (e.g int,QPoint,QString etc.)
class Prop
{
private:
void *mPointer; // should point to xy
public:
void SetPointer(void *pointer)
{
mPointer = pointer;
}
void SetGlobalVariabel() // should set xy indirect with mPointer
{
if (!mPointer) return;
switch (mValue.type())
{
*(static_cast<double*>(mPointer)) = mValue.value<double>();
break;
}
*(static_cast<int*>(mPointer)) = mValue.value<int>();
break;
}
default:
;
}
}
};
// global variable
double xy; // could be any other type (e.g int,QPoint,QString etc.)
class Prop
{
private:
QString mName;
QVariant mValue;
void *mPointer; // should point to xy
public:
void SetPointer(void *pointer)
{
mPointer = pointer;
}
void SetGlobalVariabel() // should set xy indirect with mPointer
{
if (!mPointer) return;
switch (mValue.type())
{
case (QVariant::Double): {
*(static_cast<double*>(mPointer)) = mValue.value<double>();
break;
}
case (QVariant::Int): {
*(static_cast<int*>(mPointer)) = mValue.value<int>();
break;
}
default:
;
}
}
};
To copy to clipboard, switch view to plain text mode
SetPointer(&xy) links the QVariant variable to the global variable.
SetGlobalVariable() sets the global variable.
This is not exactly what i wanted but since i only need some types of QVariant it is the fastest way to solve the problem.
A more common solution should be possible if i would know the address(pointer) where QVariant stores the value of the variable.
But at the moment the problem is solved for me.
Thanks for the help.
Bookmarks