Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register_class doesn't get called #77

Open
nmarandi opened this issue Oct 16, 2022 · 7 comments
Open

register_class doesn't get called #77

nmarandi opened this issue Oct 16, 2022 · 7 comments

Comments

@nmarandi
Copy link

nmarandi commented Oct 16, 2022

I have a code that I compile with GCC 9.4.0 and GCC 7.3.0!

The code has normal behavior with GCC 9.4.0. but with GCC 7.3.0, the register_class function doesn't get called.

If any further information is needed, let me know!

namespace qx
{

template <>
void register_class(QxClass<UserAccount> & t)
{
    qx::IxDataMember * pData = NULL;
    Q_UNUSED(pData);
    qx::IxSqlRelation * pRelation = NULL;
    Q_UNUSED(pRelation);
    qx::IxFunction * pFct = NULL;
    Q_UNUSED(pFct);
    qx::IxValidator * pValidator = NULL;
    Q_UNUSED(pValidator);

    t.setName("mixer_useraccount");

    pData = t.id(& UserAccount::username, "username", 0);

    pData = t.data(& UserAccount::password, "password", 0, true, true);

    qx::QxValidatorX<UserAccount> * pAllValidator = t.getAllValidator();
    Q_UNUSED(pAllValidator);
}

} // namespace qx

[QxOrm] execute sql query failed : SELEC FROM UserAccount
Database error number '
42601' :
QPSQL: Unable to create query
ERROR: syntax error at or near "SELEC"
LINE 1: SELEC FROM UserAccount

@nmarandi nmarandi changed the title register_class didn't get called register_class doesn't get called Oct 16, 2022
@QxOrm
Copy link
Owner

QxOrm commented Oct 17, 2022

Hello,

This is strange !
Have you tried to build and execute the sample projects available in the ./test/ directory of QxOrm package ?

@nmarandi
Copy link
Author

Hello,

This is strange ! Have you tried to build and execute the sample projects available in the ./test/ directory of QxOrm package ?

I have 20 classes that I want to persist in the database. The strange thing is that 18 of them behave normally.
The difference between classes that work and classes that don't work is that I call the qxorm functions in the member function of the class. In this state, it works normally. But when I call the qxorm function from other classes, it doesn't behave normally.

@QxOrm
Copy link
Owner

QxOrm commented Oct 18, 2022

Maybe you could provide some code to help to resolve your issue ?

  • a class which works
  • a class which doesnt work
  • an example of code which doesn't work

You can also try, at the beginning of your main function, to call :
qx::QxClassX::registerAllClasses(true);

@nmarandi
Copy link
Author

nmarandi commented Oct 19, 2022

Maybe you could provide some code to help to resolve your issue ?

  • a class which works
  • a class which doesnt work
  • an example of code which doesn't work

You can also try, at the beginning of your main function, to call : qx::QxClassX::registerAllClasses(true);

this class doesn't work.

#include "QxRegister/QxRegister.h"

struct UserAccountData {
    QString username;
    QString password;
};

QX_REGISTER_PRIMARY_KEY(UserAccountData, QString)
QX_REGISTER_HPP(UserAccountData, qx::trait::no_base_class_defined, 0)


#include <QxOrm.h>

QX_REGISTER_CPP(UserAccountData)

namespace qx
{

template <>
void register_class(QxClass<UserAccountData> & t)
{
    qDebug() << "void register_class(QxClass<UserAccountData> & t)";
    qx::IxDataMember * pData = NULL;
    Q_UNUSED(pData);
    qx::IxSqlRelation * pRelation = NULL;
    Q_UNUSED(pRelation);
    qx::IxFunction * pFct = NULL;
    Q_UNUSED(pFct);
    qx::IxValidator * pValidator = NULL;
    Q_UNUSED(pValidator);

    t.setName("mixer_useraccount");

    pData = t.id(& UserAccountData::username, "username", 0);

    pData = t.data(& UserAccountData::password, "password", 0, true, true);

    qx::QxValidatorX<UserAccountData> * pAllValidator = t.getAllValidator();
    Q_UNUSED(pAllValidator);
}

} // namespace qx

qx::QxClassX::registerAllClasses(true); doesn't work. :(

@QxOrm
Copy link
Owner

QxOrm commented Oct 19, 2022

Hello,
I think the issue is that you use the macro QX_REGISTER_HPP / QX_REGISTER_CPP without wrap them correctly in your own macro.
I would recommend :

  • try to build some projects samples from ./test/ directory of QxOrm package (for example the qxBlog project)
  • if the qxBlog project runs fine, then it could be a starter pack for your project
  • or you can also try QxEntityEditor application : you can create a project with 5 classes, and QxEntityEditor will generate the correct C++ code for your persistent classes.

@nmarandi
Copy link
Author

nmarandi commented Oct 22, 2022

Using QX_REGISTER_HPP_EXPORT_DLL and QX_REGISTER_CPP_EXPORT_DLL fix the problem. Thanks

maybe it is better to change it in the manual.

in *.h header file (containing class definition) : use QX_REGISTER_HPP(class_name, base_class, class_version) macro ;
in *.cpp source file (containing class implementation) : use QX_REGISTER_CPP(class_name) macro ;
in *.cpp source file (containing class implementation) : specialize template function : void qx::register_class(qx::QxClass & t).

@qht1003077897
Copy link

yes,QX_REGISTER_HPP AND QX_REGISTER_CPP is not available,Using QX_REGISTER_HPP_EXPORT_DLL and QX_REGISTER_CPP_EXPORT_DLL fix the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants