Compile problem

Forum for posting problems using QxOrm library

Compile problem

Postby mk33 » Sat Apr 04, 2020 6:58 pm

Hello, I try to compile my code with QxOrm.

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;
}
mk33
 
Posts: 2
Joined: Sat Apr 04, 2020 6:43 pm

Re: Compile problem

Postby qxorm » Sun Apr 05, 2020 11:53 am

Hello,

For this kind of issue, I would recommend to try QxEntityEditor application.
It will generate valid C++ code for QxOrm library.
And you can use it free of charge until 5 entities per project : so you can try to define your Item class in QxEntityEditor and see how C++ code looks like.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Compile problem

Postby mk33 » Wed Apr 08, 2020 10:35 am

Problem solved. Use special project/library for data, using dllexport/dllimport.

mk33
mk33
 
Posts: 2
Joined: Sat Apr 04, 2020 6:43 pm

Re: Compile problem

Postby qxorm » Wed Apr 08, 2020 4:18 pm

Problem solved.

Great !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron