a question about QVariant
Hi all
In the source code of Qt, we could see the below code
VS9 will report a warning:
Quote:
warning C4172: returning address of local variable or temporary
We all know returning address of local var is very dangerous!
I want to know is that(return QVariant();) correct?
Re: a question about QVariant
This is returning a name less empty object. So no probs !!
Re: a question about QVariant
Depends on the Signature.
Code:
// bad, return by reference a local variable
QVariant& myClass::myFunction() {
}
// ok, return by copy
}
// Also ok, return by reference
QVariant& myClass::myFunction(QVariant& my_variant) {
return my_variant;
}
See (for example) here for a detailed expanation
Re: a question about QVariant
Quote:
Originally Posted by
yogeshgokul
This is returning a name less empty object. So no probs !!
Thank you for replying!
What do you mean by empty object?
In Qt doc:
QVariant::QVariant ()
Constructs an invalid variant.
In Qt source code:
Code:
struct Private
{
inline Private(): type(Invalid), is_shared(false), is_null(true) { data.ptr = 0; }
inline Private(const Private &other)
: data(other.data), type(other.type),
is_shared(other.is_shared), is_null(other.is_null)
{}
union Data
{
char c;
int i;
uint u;
bool b;
double d;
qlonglong ll;
qulonglong ull;
void *ptr;
PrivateShared *shared;
} data;
uint type : 30;
uint is_shared : 1;
uint is_null : 1;
};
I deduce that the QVariant() is not empty.It at least contains type of which value is Invalid!
Re: a question about QVariant
Empty in the terms of semantics ("without any user relevant data").