Remove QVariant(int type, void *data, ...) constructor

It was marked internal anyway. Use the constructor taking a
QMetaType instead.

Change-Id: I15b9cd0911aac063a0f0fe0352fa2c84b7f7c691
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Lars Knoll 2020-06-15 09:09:08 +02:00
parent af263b003b
commit 8929c0a355
49 changed files with 101 additions and 123 deletions

View File

@ -2032,21 +2032,6 @@ QVariant::QVariant(Type type)
/*!
\internal
flags is true if it is a pointer type
*/
QVariant::QVariant(int typeId, const void *copy, uint flags)
{
if (flags) { //type is a pointer type
d = Private(QMetaType(typeId));
d.data.ptr = *reinterpret_cast<void *const*>(copy);
} else {
create(typeId, copy);
}
}
/*!
\internal
flags is true if it is a pointer type
*/
QVariant::QVariant(QMetaType type, const void *copy) : d(type)
{
@ -4307,7 +4292,7 @@ static const QVariant variantFromVariantDataHelper(const QtMetaTypePrivate::Vari
if (d.metaTypeId == qMetaTypeId<QVariant>())
v = *reinterpret_cast<const QVariant*>(d.data);
else
v = QVariant(d.metaTypeId, d.data, d.flags & ~QVariantConstructionFlags::ShouldDeleteVariantData);
v = QVariant(QMetaType(d.metaTypeId), d.data);
if (d.flags & QVariantConstructionFlags::ShouldDeleteVariantData)
QMetaType::destroy(d.metaTypeId, const_cast<void *>(d.data));
return v;

View File

@ -208,7 +208,6 @@ class Q_CORE_EXPORT QVariant
QVariant() noexcept : d() {}
~QVariant();
QVariant(Type type);
QVariant(int typeId, const void *copy, uint flags = 0); // ### Qt6 TODO deprecate
explicit QVariant(QMetaType type, const void *copy = nullptr);
QVariant(const QVariant &other);
@ -820,12 +819,12 @@ namespace QtPrivate {
if (QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QPairVariantInterfaceImpl>()) && !(typeId == qMetaTypeId<QPair<QVariant, QVariant> >())) {
QtMetaTypePrivate::QPairVariantInterfaceImpl pi = v.value<QtMetaTypePrivate::QPairVariantInterfaceImpl>();
const QtMetaTypePrivate::VariantData d1 = pi.first();
QVariant v1(d1.metaTypeId, d1.data, d1.flags);
QVariant v1(QMetaType(d1.metaTypeId), d1.data);
if (d1.metaTypeId == qMetaTypeId<QVariant>())
v1 = *reinterpret_cast<const QVariant*>(d1.data);
const QtMetaTypePrivate::VariantData d2 = pi.second();
QVariant v2(d2.metaTypeId, d2.data, d2.flags);
QVariant v2(QMetaType(d2.metaTypeId), d2.data);
if (d2.metaTypeId == qMetaTypeId<QVariant>())
v2 = *reinterpret_cast<const QVariant*>(d2.data);

View File

@ -2435,7 +2435,7 @@ void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalInd
QList<QVariant> vargs;
vargs.reserve(argc);
for (int i = 0; i < argc; ++i) {
int type = method.parameterType(i);
auto type = method.parameterMetaType(i);
vargs.append(QVariant(type, argv[i+1]));
}

View File

@ -327,7 +327,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
const int numTypes = types.count();
args.reserve(numTypes - 1);
for (int i = 1; i < numTypes; ++i)
args << QVariant(types.at(i), argv[i]);
args << QVariant(QMetaType(types.at(i)), argv[i]);
// now emit the signal with all the information
emit relaySignal(realObject, senderMetaObject, lastSignalIdx, args);

View File

@ -284,7 +284,7 @@ int QDBusAbstractInterfaceBase::qt_metacall(QMetaObject::Call _c, int _id, void
if (mp.userType() == qMetaTypeId<QDBusVariant>())
value = reinterpret_cast<const QDBusVariant*>(_a[0])->variant();
else
value = QVariant(mp.userType(), _a[0]);
value = QVariant(mp.metaType(), _a[0]);
status = d_func()->setProperty(mp, value) ? 1 : 0;
} else {
bool readStatus = d_func()->property(mp, _a[0]);

View File

@ -74,8 +74,7 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
marshaller->ba = &signature;
// run it
void *null = nullptr;
QVariant v(id, null);
QVariant v{QMetaType(id)};
QDBusArgument arg(marshaller);
QDBusMetaType::marshall(arg, v.userType(), v.constData());
arg.d = nullptr;

View File

@ -946,8 +946,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
params.append(const_cast<void *>(arg.constData()));
else if (arg.userType() == qMetaTypeId<QDBusArgument>()) {
// convert to what the function expects
void *null = nullptr;
auxParameters.append(QVariant(id, null));
auxParameters.append(QVariant(QMetaType(id)));
const QDBusArgument &in =
*reinterpret_cast<const QDBusArgument *>(arg.constData());
@ -974,10 +973,9 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
// output arguments
const int numMetaTypes = metaTypes.count();
QVariantList outputArgs;
void *null = nullptr;
if (metaTypes[0] != QMetaType::Void && metaTypes[0] != QMetaType::UnknownType) {
outputArgs.reserve(numMetaTypes - i + 1);
QVariant arg(metaTypes[0], null);
QVariant arg{QMetaType(metaTypes[0])};
outputArgs.append( arg );
params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData());
} else {
@ -985,7 +983,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
}
for ( ; i < numMetaTypes; ++i) {
QVariant arg(metaTypes[i], null);
QVariant arg{QMetaType(metaTypes[i])};
outputArgs.append( arg );
params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()));
}

View File

@ -289,7 +289,7 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
args.reserve(inputTypesCount);
int i = 1;
for ( ; i <= inputTypesCount; ++i)
args << QVariant(inputTypes[i], argv[i]);
args << QVariant(QMetaType(inputTypes[i]), argv[i]);
// make the call
QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);

View File

@ -358,8 +358,7 @@ static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant
if (id != QMetaType::QVariant && value.userType() == QDBusMetaTypeId::argument()) {
// we have to demarshall before writing
void *null = nullptr;
QVariant other(id, null);
QVariant other{QMetaType(id)};
if (!QDBusMetaType::demarshall(qvariant_cast<QDBusArgument>(value), id, other.data())) {
qWarning("QDBusConnection: type `%s' (%d) is not registered with QtDBus. "
"Use qDBusRegisterMetaType to register it",

View File

@ -67,7 +67,7 @@ public:
inline QDBusReply(const QDBusReply &) = default;
inline QDBusReply& operator=(const QDBusMessage &reply)
{
QVariant data(qMetaTypeId<Type>(), nullptr);
QVariant data(QMetaType::fromType<Type>());
qDBusReplyFill(reply, m_error, data);
m_data = qvariant_cast<Type>(data);
return *this;
@ -131,8 +131,7 @@ private:
template<> inline QDBusReply<QVariant>&
QDBusReply<QVariant>::operator=(const QDBusMessage &reply)
{
void *null = nullptr;
QVariant data(qMetaTypeId<QDBusVariant>(), null);
QVariant data(QMetaType::fromType<QDBusVariant>());
qDBusReplyFill(reply, m_error, data);
m_data = qvariant_cast<QDBusVariant>(data).variant();
return *this;

View File

@ -218,7 +218,7 @@ QBitmap::~QBitmap()
*/
QBitmap::operator QVariant() const
{
return QVariant(QMetaType::QBitmap, this);
return QVariant::fromValue(*this);
}
static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags)

View File

@ -782,7 +782,7 @@ QIcon &QIcon::operator=(const QIcon &other)
*/
QIcon::operator QVariant() const
{
return QVariant(QMetaType::QIcon, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -1083,7 +1083,7 @@ int QImage::devType() const
*/
QImage::operator QVariant() const
{
return QVariant(QMetaType::QImage, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -404,7 +404,7 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
*/
QPixmap::operator QVariant() const
{
return QVariant(QMetaType::QPixmap, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -688,7 +688,7 @@ QCursor &QCursor::operator=(const QCursor &c)
*/
QCursor::operator QVariant() const
{
return QVariant(QMetaType::QCursor, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -1390,7 +1390,7 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
*/
QKeySequence::operator QVariant() const
{
return QVariant(QMetaType::QKeySequence, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -725,7 +725,7 @@ QPalette &QPalette::operator=(const QPalette &p)
*/
QPalette::operator QVariant() const
{
return QVariant(QMetaType::QPalette, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -1977,7 +1977,7 @@ void QMatrix4x4::optimize()
*/
QMatrix4x4::operator QVariant() const
{
return QVariant(QMetaType::QMatrix4x4, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -983,7 +983,7 @@ QQuaternion QQuaternion::nlerp
*/
QQuaternion::operator QVariant() const
{
return QVariant(QMetaType::QQuaternion, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -531,7 +531,7 @@ QVector4D QVector2D::toVector4D() const
*/
QVector2D::operator QVariant() const
{
return QVariant(QMetaType::QVector2D, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -706,7 +706,7 @@ QVector4D QVector3D::toVector4D() const
*/
QVector3D::operator QVariant() const
{
return QVariant(QMetaType::QVector3D, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -608,7 +608,7 @@ QVector3D QVector4D::toVector3DAffine() const
*/
QVector4D::operator QVariant() const
{
return QVariant(QMetaType::QVector4D, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM

View File

@ -672,7 +672,7 @@ QBrush &QBrush::operator=(const QBrush &b)
*/
QBrush::operator QVariant() const
{
return QVariant(QMetaType::QBrush, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -2935,7 +2935,7 @@ bool QColor::operator!=(const QColor &color) const noexcept
*/
QColor::operator QVariant() const
{
return QVariant(QMetaType::QColor, this);
return QVariant::fromValue(*this);
}
/*! \internal

View File

@ -768,7 +768,7 @@ QColorTransform QColorSpace::transformationToColorSpace(const QColorSpace &color
*/
QColorSpace::operator QVariant() const
{
return QVariant(QMetaType::QColorSpace, this);
return QVariant::fromValue(*this);
}
/*****************************************************************************

View File

@ -408,7 +408,7 @@ QPen &QPen::operator=(const QPen &p) noexcept
*/
QPen::operator QVariant() const
{
return QVariant(QMetaType::QPen, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -716,7 +716,7 @@ QPolygon QPolygonF::toPolygon() const
*/
QPolygon::operator QVariant() const
{
return QVariant(QMetaType::QPolygon, this);
return QVariant::fromValue(*this);
}
/*****************************************************************************
@ -1040,7 +1040,7 @@ bool QPolygonF::intersects(const QPolygonF &p) const
QPolygonF::operator QVariant() const
{
return QVariant(QMetaType::QPolygonF, this);
return QVariant::fromValue(*this);
}
QT_END_NAMESPACE

View File

@ -583,7 +583,7 @@ QRegion& QRegion::operator^=(const QRegion &r)
*/
QRegion::operator QVariant() const
{
return QVariant(QMetaType::QRegion, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -2081,7 +2081,7 @@ QTransform::TransformationType QTransform::type() const
*/
QTransform::operator QVariant() const
{
return QVariant(QMetaType::QTransform, this);
return QVariant::fromValue(*this);
}

View File

@ -1726,7 +1726,7 @@ bool QFont::operator!=(const QFont &f) const
*/
QFont::operator QVariant() const
{
return QVariant(QMetaType::QFont, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -144,7 +144,7 @@ QT_BEGIN_NAMESPACE
*/
QTextLength::operator QVariant() const
{
return QVariant(QMetaType::QTextLength, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DATASTREAM
@ -895,7 +895,7 @@ QTextFormat::~QTextFormat()
*/
QTextFormat::operator QVariant() const
{
return QVariant(QMetaType::QTextFormat, this);
return QVariant::fromValue(*this);
}
/*!

View File

@ -591,7 +591,7 @@ static bool qMakeStatement(QDB2ResultPrivate* d, bool forwardOnly, bool setForwa
QVariant QDB2Result::handle() const
{
Q_D(const QDB2Result);
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hStmt);
return QVariant(QMetaType::fromType<SQLHANDLE>(), &d->hStmt);
}
/************************************/
@ -1729,7 +1729,7 @@ QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const
QVariant QDB2Driver::handle() const
{
Q_D(const QDB2Driver);
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hDbc);
return QVariant(QMetaType::fromType<SQLHANDLE>(), &d->hDbc);
}
QString QDB2Driver::escapeIdentifier(const QString &identifier, IdentifierType) const

View File

@ -1379,7 +1379,7 @@ QSqlRecord QIBaseResult::record() const
QVariant QIBaseResult::handle() const
{
Q_D(const QIBaseResult);
return QVariant(qRegisterMetaType<isc_stmt_handle>("isc_stmt_handle"), &d->stmt);
return QVariant(QMetaType::fromType<isc_stmt_handle>(), &d->stmt);
}
/*********************************/
@ -1730,7 +1730,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons
QVariant QIBaseDriver::handle() const
{
Q_D(const QIBaseDriver);
return QVariant(qRegisterMetaType<isc_db_handle>("isc_db_handle"), &d->ibase);
return QVariant(QMetaType::fromType<isc_db_handle>(), &d->ibase);
}
static ISC_EVENT_CALLBACK qEventCallback(char *result, ISC_USHORT length, const ISC_UCHAR *updated)

View File

@ -544,7 +544,7 @@ QVariant QMYSQLResult::data(int field)
return QVariant(QVariant::Type(f.type));
if (qIsInteger(f.type)) {
QVariant variant(f.type, f.outField);
QVariant variant(QMetaType(f.type), f.outField);
// we never want to return char variants here, see QTBUG-53397
if (static_cast<int>(f.type) == QMetaType::UChar)
return variant.toUInt();

View File

@ -561,7 +561,7 @@ void QOCIResultPrivate::outValues(QVariantList &values, IndicatorArray &indicato
qOraOutValue(values[i], tmpStorage, env, err);
QVariant::Type typ = values.at(i).type();
auto typ = values.at(i).metaType();
if (indicators[i] == -1) // NULL
values[i] = QVariant(typ);
else
@ -1618,8 +1618,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
if (!d->isOutValue(i))
continue;
QVariant::Type tp = boundValues.at(i).type();
if (tp != QVariant::List) {
if (auto tp = boundValues.at(i).metaType(); tp.id() != QVariant::List) {
qOraOutValue(boundValues[i], tmpStorage, d->env, d->err);
if (*columns[i].indicators == -1)
boundValues[i] = QVariant(tp);

View File

@ -1779,7 +1779,7 @@ QVariant QODBCResult::lastInsertId() const
QVariant QODBCResult::handle() const
{
Q_D(const QODBCResult);
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hStmt);
return QVariant(QMetaType::fromType<SQLHANDLE>(), &d->hStmt);
}
bool QODBCResult::nextResult()
@ -2618,7 +2618,7 @@ QString QODBCDriver::formatValue(const QSqlField &field,
QVariant QODBCDriver::handle() const
{
Q_D(const QODBCDriver);
return QVariant(qRegisterMetaType<SQLHANDLE>("SQLHANDLE"), &d->hDbc);
return QVariant(QMetaType::fromType<SQLHANDLE>(), &d->hDbc);
}
QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) const

View File

@ -112,7 +112,7 @@ QWidget *createEditor(QWidget *aParent,
const QByteArray n = editor->metaObject()->userProperty().name();
if (!n.isEmpty()) {
if (!v.isValid())
v = QVariant(editor->property(n.data()).userType(), nullptr);
v = QVariant(editor->property(n.data()).metaType());
editor->setProperty(n.data(), v);
return;
}

View File

@ -112,7 +112,7 @@ static void qSignalDumperCallback(QObject *caller, int signal_index, void **argv
Q_ASSERT(typeId != QMetaType::Void); // void parameter => metaobject is corrupt
str.append(arg)
.append('(')
.append(QVariant(typeId, argv[i + 1]).toString().toLocal8Bit())
.append(QVariant(QMetaType(typeId), argv[i + 1]).toString().toLocal8Bit())
.append(')');
}
str.append(", ");

View File

@ -221,7 +221,7 @@ private:
if (type == QMetaType::QVariant)
list << *reinterpret_cast<QVariant *>(a[i + 1]);
else
list << QVariant(type, a[i + 1]);
list << QVariant(QMetaType(type), a[i + 1]);
}
append(list);

View File

@ -531,7 +531,7 @@ void QItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con
if (!n.isEmpty()) {
if (!v.isValid())
v = QVariant(editor->property(n).userType(), (const void *)nullptr);
v = QVariant(editor->property(n).metaType());
editor->setProperty(n, v);
}
#endif

View File

@ -448,7 +448,7 @@ void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde
if (!n.isEmpty()) {
if (!v.isValid())
v = QVariant(editor->property(n).userType(), (const void *)nullptr);
v = QVariant(editor->property(n).metaType());
editor->setProperty(n, v);
}
#endif

View File

@ -439,7 +439,7 @@ void QSizePolicy::setControlType(ControlType type) noexcept
*/
QSizePolicy::operator QVariant() const
{
return QVariant(QMetaType::QSizePolicy, this);
return QVariant::fromValue(*this);
}
#ifndef QT_NO_DATASTREAM

View File

@ -275,7 +275,7 @@ struct GenericGadgetType : BaseGenericType
} else if (_c == QMetaObject::WriteProperty) {
if (_id < properties.size()) {
auto & prop = properties[_id];
prop = QVariant(prop.userType(), _a[0]);
prop = QVariant(prop.metaType(), _a[0]);
}
}
}
@ -404,7 +404,7 @@ void tst_QMetaType::registerGadget(const char *name, const QList<GadgetPropertyT
auto dynamicGadgetProperties = std::make_shared<GenericGadgetType>();
for (const auto &prop : gadgetProperties) {
int propertyType = QMetaType::type(prop.type);
dynamicGadgetProperties->properties.push_back(QVariant(QVariant::Type(propertyType)));
dynamicGadgetProperties->properties.push_back(QVariant(QMetaType(propertyType)));
auto dynamicPropery = gadgetBuilder.addProperty(prop.name, prop.type);
dynamicPropery.setWritable(true);
dynamicPropery.setReadable(true);
@ -1291,7 +1291,7 @@ void tst_QMetaType::typedConstruct()
};
registerGadget("DynamicGadget1", dynamicGadget1);
QVariant testGadget1(QVariant::Type(QMetaType::type("DynamicGadget1")));
QVariant testGadget1(QMetaType(QMetaType::type("DynamicGadget1")));
testMetaObjectWriteOnGadget(testGadget1, dynamicGadget1);
testMetaObjectReadOnGadget(testGadget1, dynamicGadget1);
@ -1303,7 +1303,7 @@ void tst_QMetaType::typedConstruct()
{"DynamicGadget1", "dynamicGadget1_prop", testGadget1}
};
registerGadget("DynamicGadget2", dynamicGadget2);
QVariant testGadget2(QVariant::Type(QMetaType::type("DynamicGadget2")));
QVariant testGadget2(QMetaType(QMetaType::type("DynamicGadget2")));
testMetaObjectWriteOnGadget(testGadget2, dynamicGadget2);
testMetaObjectReadOnGadget(testGadget2, dynamicGadget2);
auto g2mo = QMetaType::metaObjectForType(testGadget2.userType());
@ -1336,7 +1336,7 @@ void tst_QMetaType::typedConstruct()
// Test POD
QCOMPARE(podTypeId, QMetaType::type(podTypeName));
QVariant podVariant{QVariant::Type(podTypeId)};
QVariant podVariant{QMetaType(podTypeId)};
QCOMPARE(myPodTesData, static_cast<const GenericPODType *>(reinterpret_cast<const BaseGenericType *>(podVariant.constData()))->podData);
QVariant podVariant1{podVariant};

View File

@ -356,7 +356,7 @@ void tst_QVariant::constructor_invalid()
}
{
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type"));
QVariant variant(typeId, /* copy */ 0);
QVariant variant(QMetaType(typeId), /* copy */ nullptr);
QVERIFY(!variant.isValid());
QVERIFY(variant.isNull());
QCOMPARE(variant.userType(), int(QMetaType::UnknownType));
@ -403,7 +403,7 @@ void tst_QVariant::isNull()
QVariant varLL( (qlonglong)0 );
QVERIFY( !varLL.isNull() );
QVariant var8(QMetaType::Nullptr, nullptr);
QVariant var8(QMetaType(QMetaType::Nullptr), nullptr);
QVERIFY(var8.isNull());
var8 = QVariant::fromValue<std::nullptr_t>(nullptr);
QVERIFY(var8.isNull());
@ -412,12 +412,12 @@ void tst_QVariant::isNull()
var9 = QVariant::fromValue<QJsonValue>(QJsonValue(QJsonValue::Null));
QVERIFY(!var9.isNull());
QVariant var10(QMetaType::VoidStar, nullptr);
QVariant var10(QMetaType(QMetaType::VoidStar), nullptr);
QVERIFY(var10.isNull());
var10 = QVariant::fromValue<void*>(nullptr);
QVERIFY(var10.isNull());
QVariant var11(QMetaType::QObjectStar, nullptr);
QVariant var11(QMetaType(QMetaType::QObjectStar), nullptr);
QVERIFY(var11.isNull());
var11 = QVariant::fromValue<QObject*>(nullptr);
QVERIFY(var11.isNull());
@ -1305,27 +1305,27 @@ void tst_QVariant::writeToReadFromDataStream_data()
QTest::newRow( "regularexpression_empty" ) << QVariant(QRegularExpression()) << false;
// types known to QMetaType, but not part of QVariant::Type
QTest::newRow("QMetaType::Long invalid") << QVariant(QMetaType::Long, (void *) 0) << true;
QTest::newRow("QMetaType::Long invalid") << QVariant(QMetaType(QMetaType::Long), nullptr) << true;
long longInt = -1l;
QTest::newRow("QMetaType::Long") << QVariant(QMetaType::Long, &longInt) << false;
QTest::newRow("QMetaType::Short invalid") << QVariant(QMetaType::Short, (void *) 0) << true;
QTest::newRow("QMetaType::Long") << QVariant(QMetaType(QMetaType::Long), &longInt) << false;
QTest::newRow("QMetaType::Short invalid") << QVariant(QMetaType(QMetaType::Short), nullptr) << true;
short shortInt = 1;
QTest::newRow("QMetaType::Short") << QVariant(QMetaType::Short, &shortInt) << false;
QTest::newRow("QMetaType::Char invalid") << QVariant(QMetaType::Char, (void *) 0) << true;
QTest::newRow("QMetaType::Short") << QVariant(QMetaType(QMetaType::Short), &shortInt) << false;
QTest::newRow("QMetaType::Char invalid") << QVariant(QMetaType(QMetaType::Char), nullptr) << true;
char ch = 'c';
QTest::newRow("QMetaType::Char") << QVariant(QMetaType::Char, &ch) << false;
QTest::newRow("QMetaType::ULong invalid") << QVariant(QMetaType::ULong, (void *) 0) << true;
QTest::newRow("QMetaType::Char") << QVariant(QMetaType(QMetaType::Char), &ch) << false;
QTest::newRow("QMetaType::ULong invalid") << QVariant(QMetaType(QMetaType::ULong), nullptr) << true;
ulong ulongInt = 1ul;
QTest::newRow("QMetaType::ULong") << QVariant(QMetaType::ULong, &ulongInt) << false;
QTest::newRow("QMetaType::UShort invalid") << QVariant(QMetaType::UShort, (void *) 0) << true;
QTest::newRow("QMetaType::ULong") << QVariant(QMetaType(QMetaType::ULong), &ulongInt) << false;
QTest::newRow("QMetaType::UShort invalid") << QVariant(QMetaType(QMetaType::UShort), nullptr) << true;
ushort ushortInt = 1u;
QTest::newRow("QMetaType::UShort") << QVariant(QMetaType::UShort, &ushortInt) << false;
QTest::newRow("QMetaType::UChar invalid") << QVariant(QMetaType::UChar, (void *) 0) << true;
QTest::newRow("QMetaType::UShort") << QVariant(QMetaType(QMetaType::UShort), &ushortInt) << false;
QTest::newRow("QMetaType::UChar invalid") << QVariant(QMetaType(QMetaType::UChar), nullptr) << true;
uchar uch = 0xf0;
QTest::newRow("QMetaType::UChar") << QVariant(QMetaType::UChar, &uch) << false;
QTest::newRow("QMetaType::Float invalid") << QVariant(QMetaType::Float, (void *) 0) << true;
QTest::newRow("QMetaType::UChar") << QVariant(QMetaType(QMetaType::UChar), &uch) << false;
QTest::newRow("QMetaType::Float invalid") << QVariant(QMetaType(QMetaType::Float), nullptr) << true;
float f = 1.234f;
QTest::newRow("QMetaType::Float") << QVariant(QMetaType::Float, &f) << false;
QTest::newRow("QMetaType::Float") << QVariant(QMetaType(QMetaType::Float), &f) << false;
CustomStreamableClass custom = {123};
QTest::newRow("Custom type") << QVariant::fromValue(custom) << false;
}
@ -1990,35 +1990,35 @@ void tst_QVariant::basicUserType()
QVariant v;
{
int i = 7;
v = QVariant(QMetaType::Int, &i);
v = QVariant(QMetaType(QMetaType::Int), &i);
}
QCOMPARE(v.type(), QVariant::Int);
QCOMPARE(v.toInt(), 7);
{
QString s("foo");
v = QVariant(QMetaType::QString, &s);
v = QVariant(QMetaType(QMetaType::QString), &s);
}
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("foo"));
{
double d = 4.4;
v = QVariant(QMetaType::Double, &d);
v = QVariant(QMetaType(QMetaType::Double), &d);
}
QCOMPARE(v.type(), QVariant::Double);
QCOMPARE(v.toDouble(), 4.4);
{
float f = 4.5f;
v = QVariant(QMetaType::Float, &f);
v = QVariant(QMetaType(QMetaType::Float), &f);
}
QCOMPARE(v.userType(), int(QMetaType::Float));
QCOMPARE(v.toDouble(), 4.5);
{
QByteArray ba("bar");
v = QVariant(QMetaType::QByteArray, &ba);
v = QVariant(QMetaType(QMetaType::QByteArray), &ba);
}
QCOMPARE(v.type(), QVariant::ByteArray);
QCOMPARE(v.toByteArray(), QByteArray("bar"));
@ -2181,12 +2181,12 @@ void tst_QVariant::saveLoadCustomTypes()
QByteArray data;
Blah i = { 42 };
int tp = qRegisterMetaType<Blah>("Blah");
auto tp = QMetaType::fromType<Blah>();
QVariant v = QVariant(tp, &i);
qRegisterMetaTypeStreamOperators<Blah>("Blah");
QCOMPARE(v.userType(), tp);
QCOMPARE(v.userType(), tp.id());
QCOMPARE(v.type(), QVariant::UserType);
{
QDataStream stream(&data, QIODevice::WriteOnly);
@ -2239,10 +2239,10 @@ void tst_QVariant::variantMap()
QCOMPARE(map2.value("test").toInt(), 42);
QCOMPARE(map2, map);
QVariant v2 = QVariant(QMetaType::type("QVariantMap"), &map);
QVariant v2 = QVariant(QMetaType::fromType<QVariantMap>(), &map);
QCOMPARE(qvariant_cast<QVariantMap>(v2).value("test").toInt(), 42);
QVariant v3 = QVariant(QMetaType::type("QMap<QString, QVariant>"), &map);
QVariant v3 = QVariant(QMetaType::fromType<QMap<QString, QVariant>>(), &map);
QCOMPARE(qvariant_cast<QVariantMap>(v3).value("test").toInt(), 42);
QHash<QString, QVariant> hash;
@ -2264,10 +2264,10 @@ void tst_QVariant::variantHash()
QCOMPARE(hash2.value("test").toInt(), 42);
QCOMPARE(hash2, hash);
QVariant v2 = QVariant(QMetaType::type("QVariantHash"), &hash);
QVariant v2 = QVariant(QMetaType::fromType<QVariantHash>(), &hash);
QCOMPARE(qvariant_cast<QVariantHash>(v2).value("test").toInt(), 42);
QVariant v3 = QVariant(QMetaType::type("QHash<QString, QVariant>"), &hash);
QVariant v3 = QVariant(QMetaType::fromType<QHash<QString, QVariant>>(), &hash);
QCOMPARE(qvariant_cast<QVariantHash>(v3).value("test").toInt(), 42);
QMap<QString, QVariant> map;
@ -2299,7 +2299,7 @@ void tst_QVariant::qvariant_cast_QObject_data()
QTest::addColumn<bool>("isNull");
QObject *obj = new QObject;
obj->setObjectName(QString::fromLatin1("Hello"));
QTest::newRow("from QObject") << QVariant(QMetaType::QObjectStar, &obj) << true << false;
QTest::newRow("from QObject") << QVariant(QMetaType(QMetaType::QObjectStar), &obj) << true << false;
QTest::newRow("from QObject2") << QVariant::fromValue(obj) << true << false;
QTest::newRow("from String") << QVariant(QLatin1String("1, 2, 3")) << false << false;
QTest::newRow("from int") << QVariant((int) 123) << false << false;
@ -3559,7 +3559,7 @@ void tst_QVariant::variantInVariant()
QCOMPARE((int)var8.type(), (int)QVariant::String);
QCOMPARE(qvariant_cast<QString>(QVariant(qvariant_cast<QVariant>(var8))), str);
QVariant var9(qMetaTypeId<QVariant>(), &var1);
QVariant var9(QMetaType::fromType<QVariant>(), &var1);
QCOMPARE(var9.userType(), qMetaTypeId<QVariant>());
QCOMPARE(qvariant_cast<QVariant>(var9), var1);
}
@ -3817,8 +3817,8 @@ void tst_QVariant::debugStream_data()
}
}
QTest::newRow("QBitArray(111)") << QVariant(QBitArray(3, true)) << qMetaTypeId<QBitArray>();
QTest::newRow("CustomStreamableClass") << QVariant(qMetaTypeId<CustomStreamableClass>(), 0) << qMetaTypeId<CustomStreamableClass>();
QTest::newRow("MyClass") << QVariant(qMetaTypeId<MyClass>(), 0) << qMetaTypeId<MyClass>();
QTest::newRow("CustomStreamableClass") << QVariant(QMetaType::fromType<CustomStreamableClass>(), 0) << qMetaTypeId<CustomStreamableClass>();
QTest::newRow("MyClass") << QVariant(QMetaType::fromType<MyClass>(), 0) << qMetaTypeId<MyClass>();
QTest::newRow("InvalidVariant") << QVariant() << int(QMetaType::UnknownType);
QTest::newRow("CustomQObject") << QVariant::fromValue(this) << qMetaTypeId<tst_QVariant*>();
}

View File

@ -134,7 +134,7 @@ void tst_QGuiVariant::constructor_invalid()
}
{
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(typeId, /* copy */ 0);
QVariant variant(QMetaType(typeId), nullptr);
QVERIFY(!variant.isValid());
QCOMPARE(variant.userType(), int(QMetaType::UnknownType));
}

View File

@ -317,14 +317,14 @@ void tst_Cmptest::compare_tostring_data()
QTest::newRow("string, null user type")
<< QVariant::fromValue(QString::fromLatin1("A simple string"))
<< QVariant(QVariant::Type(qRegisterMetaType<PhonyClass>("PhonyClass")))
<< QVariant(QMetaType::fromType<PhonyClass>())
;
PhonyClass fake1 = {1};
PhonyClass fake2 = {2};
QTest::newRow("both non-null user type")
<< QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)&fake1)
<< QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)&fake2)
<< QVariant(QMetaType::fromType<PhonyClass>(), (const void*)&fake1)
<< QVariant(QMetaType::fromType<PhonyClass>(), (const void*)&fake2)
;
}

View File

@ -83,7 +83,7 @@ void tst_QWidgetsVariant::constructor_invalid()
}
{
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(typeId, /* copy */ 0);
QVariant variant(QMetaType(typeId), nullptr);
QVERIFY(!variant.isValid());
QCOMPARE(variant.userType(), int(QMetaType::UnknownType));
}

View File

@ -349,7 +349,7 @@ void tst_qvariant::createCoreType()
QFETCH(int, typeId);
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i)
QVariant(typeId, (void *)0);
QVariant(QMetaType(typeId));
}
}
@ -365,11 +365,11 @@ void tst_qvariant::createCoreTypeCopy_data()
void tst_qvariant::createCoreTypeCopy()
{
QFETCH(int, typeId);
QVariant other(typeId, (void *)0);
QVariant other(typeId);
const void *copy = other.constData();
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i)
QVariant(typeId, copy);
QVariant(QMetaType(typeId), copy);
}
}

View File

@ -70,7 +70,7 @@ void tst_QGuiVariant::createGuiType()
QFETCH(int, typeId);
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i)
QVariant(typeId, (void *)0);
QVariant(QMetaType(typeId));
}
}
@ -86,11 +86,11 @@ void tst_QGuiVariant::createGuiTypeCopy_data()
void tst_QGuiVariant::createGuiTypeCopy()
{
QFETCH(int, typeId);
QVariant other(typeId, (void *)0);
QVariant other((QMetaType(typeId)));
const void *copy = other.constData();
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i)
QVariant(typeId, copy);
QVariant(QMetaType(typeId), copy);
}
}