0
I am developing a generic DAO class in Qt, but when I compile I get the following error, when I call any method of my DAO object:
Debug\debug\main.o:-1: In function Z5qMainiPPc':
undefined reference to bool DAO::add<Product>(Product*)'
collect2.exe:-1: error: error: ld returned 1 exit status
The error occurs here dao.add(produto);
or here dao.remove(produto);
I wonder what I might be doing wrong .-.
Main
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
//Teste
Product *produto = new Product();
DAO dao;
produto->setCode("123456");
produto->setName("Teste");
produto->setPrice(10.33);
produto->setUnityMeasure("KG");
dao.add(produto);
//dao.remove(produto);
//Fim Teste
return app.exec();
}
Headlines
#ifndef DAO_H
#define DAO_H
#include <QObject>
class DAO:public QObject
{
Q_OBJECT
public:
DAO();
template<typename T> bool change(T *entity);
template<typename T> bool remove(T *entity);
template<typename T> bool add(T *entity);
template<typename T> T *find(T *entity);
template<typename T> QList<T *> *findAll();
};
#endif // DAO_H
Implementation
#include "dao.h"
DAO::DAO()
{
}
template<typename T>
bool DAO::change(T *entity)
{
return false;
}
template<typename T>
bool DAO::remove(T *entity)
{
return false;
}
template<typename T>
bool DAO::add(T *entity)
{
return false;
}
template<typename T>
T *DAO::find(T *entity)
{
return NULL;
}
template<typename T>
QList<T *> *DAO::findAll()
{
return NULL;
}
That way you passed I had implemented tbm and had given the same problem. I was able to compile right after I put everything in the same file. I basically took the cpp file and just left the header.
– Jhonny Rm