Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a null value with Qt?

Tags:

c++

sql

null

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.

like image 337
abatishchev Avatar asked Dec 03 '08 21:12

abatishchev


2 Answers

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.

like image 135
Johannes Schaub - litb Avatar answered Sep 19 '22 19:09

Johannes Schaub - litb


Answering the second question, QString can be null.

like image 38
0xF Avatar answered Sep 21 '22 19:09

0xF