How to insert a null value with Qt?


Tip me plase, how to insert a null value into table using Trolltech Qt 4.x SQL classes? QSqlQuery, I guess, or something else from QtNetwork. As analog of it, in .NET there is the System.DbNull class, which represents sql NULL.

And what type should I use for some object's property, that can hold both null-value and QString? In C# I could use System.Object.

10/21/2010 12:07:29 PM

Accepted Answer

From QSqlQuery::addBindValue documentation:

To bind a NULL value, use a null QVariant; for example, use QVariant(QVariant::String) if you are binding a string.

12/3/2008 9:41:11 PM

The question is for QT 4, but I think it's worth mentioning that in QT 5 you have only to pass a NULL value.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow