- Code: Select all
debug/MainWindow.o: In function `void qx::register_class<qx::QxClass<Item> >(qx::QxClass<Item>&)':
D:\projects\build-TaQxOrm-Desktop_Qt_5_12_6_MinGW_64_bit-Debug\TaQxOrm/../../TaQxOrm/libs/QxOrm/include/QxRegister/QxClass.h:71: multiple definition of `void qx::register_class<qx::QxClass<Item> >(qx::QxClass<Item>&)'
debug/Item.o:D:\projects\build-TaQxOrm-Desktop_Qt_5_12_6_MinGW_64_bit-Debug\TaQxOrm/../../TaQxOrm/TaQxOrm/data/Item.cpp:7: first defined here
When commenting these lines in MainWindow.cpp, it's ok and no compile error.
- Code: Select all
QSqlError daoError = qx::dao::create_table<Item>();
qDebug() << qx::dao::count<Item>();
Item.h
- Code: Select all
#ifndef ITEM_H
#define ITEM_H
#include <QString>
#include <QxOrm.h>
class Item
{
public:
Item();
virtual ~Item();
long id_;
QString name_;
QString description_;
};
QX_REGISTER_HPP(Item, qx::trait::no_base_class_defined, 0)
#endif // ITEM_H
Item.cpp
- Code: Select all
#include "Item.h"
QX_REGISTER_CPP(Item)
namespace qx {
template <> void register_class(QxClass<Item> &t)
{
t.setName("items");
t.id(&Item::id_, "id_key");
t.data(&Item::name_, "name");
t.data(&Item::description_, "description");
}
}
Item::Item()
: id_(0)
{
}
Item::~Item()
{
}
MainWindow.h
- Code: Select all
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
MainWindow.cpp
- Code: Select all
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QDebug>
#include <QxOrm.h>
#include "data/Item.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qx::QxSqlDatabase::getSingleton()->setDriverName("QPSQL");
qx::QxSqlDatabase::getSingleton()->setDatabaseName("xxx");
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
qx::QxSqlDatabase::getSingleton()->setUserName("xxx");
qx::QxSqlDatabase::getSingleton()->setPassword("xxx");
QSqlError daoError = qx::dao::create_table<Item>();
qDebug() << qx::dao::count<Item>();
}
MainWindow::~MainWindow()
{
delete ui;
}