How can I corretcly declare a QVariant that will map to NULL in an SQLite tabe?
-
Hi all,
Qt 6.8 introduced some new deprecation warnings, among others that one shouldn't
QVariant(QVariant::Type type)
anymore.Until now, I used this static constant here to get a
NULL
value when it's inserted into an SQLite table:static const QVariant s_sqliteNull(QVariant::Int);
I now replaced this using the advised
QMetaType
declaration withstatic const QVariant s_sqliteNull(QMetaType(QMetaType::Int));
which seemed to work fine. However, I now tried to compile my stuff using Clang and not GCC, and it seems this one doesn't like this approach: I get:
.../Database.cpp:746:43: error: conversion function from 'const QVariant ()' to 'const QVariant' invokes a deleted function 746 | s_sqliteNull, | ^~~~~~~~~~~~ /usr/include/qt6/QtCore/qvariant.h:314:5: note: 'QVariant<const QVariant (*)(), false>' has been explicitly marked deleted here 314 | QVariant(T) = delete; | ^ /usr/include/qt6/QtCore/qlist.h:289:43: note: passing argument to parameter 'args' here 289 | inline QList(std::initializer_list<T> args) | ^ .../Database.cpp:1535:42: error: incompatible operand types ('int' and 'const QVariant (*)()') 1535 | query.bindValue(1, markerId != 0 ? markerId : s_sqliteNull); | ^ ~~~~~~~~ ~~~~~~~~~~~~
I don't fully get this. How can I correctly declare a variable that will map to QSLite's
NULL
that both GCC and CLang like?Thanks for all help!
-
What's wrong with
QVariant()
? -
-
Excited to know more about this qvariant.
-
@GabrielBruce
What's to be excited about and what more do you want to learn? :)QVariant()
returns a default, invalidQVariant
, and you can e.g. pass that as a bound value where you would useNULL
in SQL.