I have a couple of classes:
A.h
class Abase_obj : public QObject
{
Q_OBJECT
Q_PROPERTY(QAction* playAction READ playAction CONSTANT)
public:
Abase_obj(QObject* parent = nullptr) : QObject(parent) {}
virtual QAction* playAction() = 0;
signals:
void someSignal()
slots:
virtual void baseSlot() = 0;
};
template <class T>
class Abase : public Abase_obj
{
public:
Abase(QObject* parent = nullptr) : Abase_obj(parent) {...}
void baseSlot() override;
QAction* playAction() override;
protected:
QWeakPointer<T> m_currentItem;
};
template <class T>
Abase<T>::baseSlot() {
auto item = m_currentItem.lock();
item->someMethodOfTemplateClass(); // here is the error
}
B_inh.h
#include "A.h"
class MediaItem;
class B_inh : public Abase<MediaItem>
{
Q_OBJECT
Q_PROPERTY(MediaItem* getItem READ getItem)
public:
// constructor
MediaItem* getItem();
public slot:
// some new slot
}
So I use Abase_obj as I can't type Q_OBJECT macro in the templated class and define there some slots and signals. I know that I can define there slots which doesn't has templated parametres. But I am using the template method directly in this slot. But as Abase_obj metaobject doesn't know about this class, I get the error: error: C2039: 'someMethodOfTemplateClass': is not a member of 'QSharedPointer' and error: C2027: use of undefined type 'MediaItem'. So I have 2 questions: first one is how should I implement this slot so it could work, and the second question is in the comment above.
Upd: If I make #include "MediaItem.h" instead of forward declaring it, I am getting errors:
LNK2001: unresolved external symbol "public: static struct QMetaObject const Abase_obj::staticMetaObject" : in file B_inh.cpp.obj
LNK2001: unresolved external symbol "public: virtual void * __cdecl Abase_obj::qt_metacast(char const *)" : in file B_inh.cpp.obj
LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Abase_obj::metaObject(void)const " : in file B_inh.cpp.obj
If I remove Q_OBJECT macro and all Q_PROPERTies from Abase_obj and add them to the B_inh class, everything is compiling and working, but I don't want to implement these properties every time in all of the derived classes
MediaItemis declared instead of forward declaring it? - vahanchomoc? I used a qmake project that handles that automatically. - JarMan