I am working on a QT based application.One of of my class is a child class of QAbstractTableModel. The data function has a return type of QVariant(Union).But i want to return a custom type std::vector<QString>
Came to know about Q_DECLARE_METATYPE();
It makes new types available to QVariant.
-Test Case Code-
#include <QApplication>
#include <QMetaType>
#include <vector>
#include<QVariant>
Q_DECLARE_METATYPE(std::vector<QString>);
QVariant data(int role)
{
std::vector<QString> test1;
test1.push_back("Dtd");
test1.push_back("Dtd");
return test1;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
data(1);
return app.exec();
}
I am getting this error
error: could not convert ‘test1’ from ‘std::vector< QString >’ to ‘QVariant’
I am missing out something.Please Help