PDA

View Full Version : QVariant question



yunpeng880
4th March 2009, 02:18
question:

QVariant test("10.23"); //define a QVariant object
test.canConvert(QVariant::DateTime)==true ? //the convert is success why?

why ? the test object can convert to datetime ? i do't understand
hope somebody help me ,thank

aamer4yu
4th March 2009, 04:50
Why shouldnt it be success ??
QVariant supports QDateTime,,, and also QDateTime can form a datetime from string (QDateTime::fromString) . So probably canConvert checks if it can form a valid QDateTime object from string, if valid, it returns success

yunpeng880
5th March 2009, 00:43
code is :
QString str="kkk";
QDateTime qdt=QDateTime::fromQString(str);
qdt.canConvert(QVariant::DateTime)==true ?//it's puzzle
why?