Page 1 of 1

Problem caliing model with relationship from main.cpp

PostPosted: Fri Jul 08, 2016 7:51 pm
by algogr
Hello everyone,

I have problem finding the way to call model with relationships from main.cpp.
I have created the model/view library through QxEE but when i try to instantiate a class i get complier errors

Here is my main.cpp
Code: Select all
#include "precompiled.h"
#include <QGuiApplication>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QxMemLeak.h>
#include <QQmlContext>

#include "export.h"

#include "tasks.gen.h"


#include "hourglassqx_precompiled_header.model_view.gen.h"
#include "hourglassqx_export.model_view.gen.h"

//#include "hourglassqx_all_include.model_view.gen.h"

#include "tasks.model_view.gen.h"
int main(int argc, char *argv[])
{

    QApplication app(argc, argv);
    qx::QxSqlDatabase::getSingleton()->setDriverName("QMYSQL");
    qx::QxSqlDatabase::getSingleton()->setDatabaseName("hourglass_test");
    qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
    qx::QxSqlDatabase::getSingleton()->setPort(3306);
    qx::QxSqlDatabase::getSingleton()->setUserName("root");
    qx::QxSqlDatabase::getSingleton()->setPassword("");
   
    qx::IxModel* tModel= new qx::QxModel<model_view::tasks_model>;
    tModel->qxFetchAll();
    qAssert(tModel->rowCount()!=0);
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("taskModel",tModel);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}



Is there anything wrong with the includes?
Thanks in advance

Re: Problem caliing model with relationship from main.cpp

PostPosted: Fri Jul 08, 2016 8:37 pm
by qxorm
Hello,

In your main.cpp, you wrote :
Code: Select all
    qx::IxModel* tModel= new qx::QxModel<model_view::tasks_model>;
    tModel->qxFetchAll();


But your model_view::tasks_model class is already a qx::QxModel<T> : it inherits from qx::QxModel<T>.
So just write :
Code: Select all
    qx::IxModel* tModel = new model_view::tasks_model();
    tModel->qxFetchAll();

Re: Problem caliing model with relationship from main.cpp

PostPosted: Sat Jul 09, 2016 9:33 am
by algogr
Thank you very much. I didn't pay attention to the generated classes. Now it compiles without problem.Thanks again

Re: Problem caliing model with relationship from main.cpp

PostPosted: Mon Jul 11, 2016 7:39 am
by qxorm
Now it compiles without problem.Thanks again

Great !