[Development] Fwd: Re: Proposing QSqlQuery syntax sugar

Thiago A. CorrĂȘa thiago.correa at gmail.com
Wed Sep 19 15:59:39 CEST 2012


On Wed, Sep 19, 2012 at 6:32 AM, Andras Mantia <andras.mantia at kdab.com> wrote:
>
> As adding a new non-virtual function is binary compatible, there should be
> no problem to add a QSqlQuery::value(const QString&) method in 5.1.
>

Ah, cool. I wasn't sure about that. I shall then send a patch for 5.1
branch when it's ready and ask Mark Brand, Thanks.

Currently I'm using this aproach with my own class that inherits from
QSqlQuery. I guess showing the code helps understand:

	template<typename T>
	inline T value(const QString& fieldName) const
	{ return value(fieldName).value<T>(); }

	template<typename T>
	inline T value(int field) const
	{ return value(field).value<T>(); }

        QVariant value( const QString& fieldName ) const
        {
            int index = record().indexOf(fieldName);
	    if ( index < 0 )
                qWarning( QString("Unknown field %1").arg(fieldName) );

	    return QSqlQuery::value( index );
        }



More information about the Development mailing list