[Development] QOptional

Thiago Macieira thiago.macieira at intel.com
Thu Aug 21 00:07:52 CEST 2014


On Wednesday 20 August 2014 20:49:03 Marc Mutz wrote:
> I don't find the QVariant::isNull behaviour any useful or intuitive. It's
> too  smart. You can always use v.value<T>().isNull() because value() will
> return a default-constructed T if invalid.

I agree it's not intuitive, but it's there and this feature is used by QtSql.

When getting a nullable column, a null entry is signalled by a typed QVariant 
for which isNull() == true.

I'd have preferred that QtSql use optionals to indicate such columns:

	varchar		=> QOptional<QString>
	varchar not null	=> QString

The question I have is: how can we prepare a transition from current state 
(both a QString) in such a way that doesn't break existing code?

Should it be a connection-time option for QSqlDatabase? Maybe a query-time 
option?

The goal should be to add this feature in Qt 5 and convince people to switch 
to the new behaviour, so we might be able to deprecate the nullable QVariant 
in Qt 5 and remove by Qt 6.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list