So I have a custom class Foo which has been registered as a metatype using the Q_DECLARE_METATYPE(Foo)
macro at the end of the class definition.
I can set items within a list, check to see if canConvert, but when I try to actually make an item of type Foo things fail at compile time.
Using QVariant passed in from a QModelIndex &index
:
Foo item(index.data(Qt::DisplayRole).value<Foo>())
fails with the following error(s):
no matching function for call to 'namespace::Foo::Foo(namespace::Foo)'
In instantiation of 'T qvariant_cast(const Foo&) [with T = namesapce::Foo]':
required from 'T QVariant::value() const [with T = namespace::Foo]'
no matching function for call to 'namespace::Foo::Foo(const namespace::Foo &)'
no matching function for call to 'namespace::Foo::Foo(const namespace::Foo&)'
no matching function for call to 'namespace::Foo::Foo(const namespace::Foo)'
In member function 'T QVariant::value() const [with T = namespace::Foo]'
all from file qvariant.h
What am I doing wrong here? My class has the following constructors:
Foo::Foo(const Foo &)
Foo::Foo()
The header is as follows:
namespace a {
namespace b {
class Foo {
explicit Foo();
explicit Foo(const Foo &a);
...
};
} // b
} // a
Q_DECLARE_METATYPE(a::b::Foo)