I've made some changes and I now get a slightly different result. I've changed my earlier code around such that the metatype is a pointer to a CustomVector and commented out the default constructor as below.
customvector.h
// ... necessary includes here ...
class CustomVector : public QVector< QHash<QString, QVariant> > { ... };
Q_DECLARE_METATYPE(CustomVector *) // <-- added pointer symbol
#ifdef QT_DEBUG
#include <QtTest>
class TestCustomVector
: public QObject{
Q_OBJECT
private slots:
void isNull_data();
void isNull();
};
#endif // QT_DEBUG
// ... necessary includes here ...
class CustomVector : public QVector< QHash<QString, QVariant> > { ... };
Q_DECLARE_METATYPE(CustomVector *) // <-- added pointer symbol
#ifdef QT_DEBUG
#include <QtTest>
class TestCustomVector : public QObject
{
Q_OBJECT
private slots:
void isNull_data();
void isNull();
};
#endif // QT_DEBUG
To copy to clipboard, switch view to plain text mode
customvector.cpp
// ... CustomVector functions including an isNull() function ...
#ifdef QT_DEBUG
void TestCustomVector::isNull_data()
{
QTest::addColumn<CustomVector *>("CustomVector"); // <-- added pointer symbol
QTest::addColumn<bool>("Result");
// CustomVector cv_default(); // <-- commented out
CustomVector cv_notNull(/* ... parameters giving a not null state... */);
CustomVector cv_null(/* ... parameters giving a null state... */)
// QTest::newRow("Default Constructor") // <-- commented out
// << &cv_default << true;
QTest::newRow("Basic Constructor, Fully Specified")
<< &cv_notNull << false;
QTest::newRow("Basic Constructor, Partially Specified")
<< &cv_null << true; // <-- corrected this line from earlier post
}
void TestCustomVector::isNull()
{
QFETCH(CustomVector *, customVector); // <-- added pointer symbol
QFETCH(bool, result);
QCOMPARE(customVector, result);
}
#endif // QT_DEBUG
// ... CustomVector functions including an isNull() function ...
#ifdef QT_DEBUG
void TestCustomVector::isNull_data()
{
QTest::addColumn<CustomVector *>("CustomVector"); // <-- added pointer symbol
QTest::addColumn<bool>("Result");
// CustomVector cv_default(); // <-- commented out
CustomVector cv_notNull(/* ... parameters giving a not null state... */);
CustomVector cv_null(/* ... parameters giving a null state... */)
// QTest::newRow("Default Constructor") // <-- commented out
// << &cv_default << true;
QTest::newRow("Basic Constructor, Fully Specified")
<< &cv_notNull << false;
QTest::newRow("Basic Constructor, Partially Specified")
<< &cv_null << true; // <-- corrected this line from earlier post
}
void TestCustomVector::isNull()
{
QFETCH(CustomVector *, customVector); // <-- added pointer symbol
QFETCH(bool, result);
QCOMPARE(customVector, result);
}
#endif // QT_DEBUG
To copy to clipboard, switch view to plain text mode
The entire program compiles and I have the following linker errors. Note that the CustomVector is part of a library with the same name.
libcustomvector.a(customvector.o): In function `TestCustomVector::isNull()':
customvector/customvector.cpp:108: undefined reference to `bool QTest::qCompare<CustomVector*, bool>(CustomVector* const&, bool const&, char const*, char const*, char const*, int)'
collect2: ld returned 1 exit status
I don't think this is progress because I don't think it's appropriate for an implicitly-shared class like CustomVector (extending QVector) to be metatype'd as a pointer.
What is going on here?
Bookmarks