Nested "role" possible in Model/View/QML?

Forum for posting problems using QxOrm library

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Wed May 04, 2016 2:04 pm

Results of another test...

Code: Select all
text: "Address = " + customersModel.getModelValue(0, "cmr_default_cad_id")


Works ok and returns the role/columnn ID value from the database


And if I try your other suggestion (and don't use the delegate class at all)

Code: Select all
        ListView {
        model: customersModel.cmr_default_cad_id(0)
        delegate: Row {
            Text { text: "address: " + cad_address_1 }
           }
        }



I get the error

Code: Select all
qrc:/pages/customersPage.qml:37: TypeError: Property 'cmr_default_cad_id' of object qx::IxModel(0x54f95e0) is not a function
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby qxorm » Wed May 04, 2016 2:04 pm

Yesterday, you renamed cmr_default_cad_id() Q_INVOKABLE function to cmr_default_cad().
Did you go back to original function name generated by QxEntityEditor ?
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Wed May 04, 2016 2:06 pm

qxorm wrote:Yesterday, you renamed cmr_default_cad_id Q_INVOKABLE function to cmr_default_cad.
Did you go back to original function name generated by QxEntityEditor ?


Yes I have reverted my source code. I will try another rebuild all of the entire project (because once again, after the revert, Visual Studio only did partial build of the model DLL).
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Wed May 04, 2016 2:40 pm

Same results after complete rebuild, so still no obvious access to the data-model behind the role.
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby qxorm » Wed May 04, 2016 3:03 pm

Ok, the only thing I can do for now for you is to provide you the tests I did this morning with the qxBlogModelView sample project.

So I attach to this topic the qxBlogModelView.zip file which contains my tests.
You can unzip it and replace this sample project in the ./test/ directory of QxOrm package.

I added to this sample project a third screen to show how to display relationship values.

The interesting part for you is :
- the ./qt/rcc/documents/main_relationship.qml QML file ;
- the way this component is loaded :
Code: Select all
void test_qml_view_with_relationship()
{
#if (QT_VERSION >= 0x050000)
   qx::IxModel * pModel = new model_view::blog_model();
   pModel->qxFetchAll(QStringList() << "*");

   QQuickView qmlView;
   QString sQmlFile = "qrc:/documents/main_relationship.qml";

   qmlView.rootContext()->setContextProperty("myModel", pModel);
   qmlView.setSource(QUrl(sQmlFile));
   qmlView.show();
   qApp->exec();
#endif // (QT_VERSION >= 0x050000)
}


EDIT : in a previous answer, you wrote :
Code: Select all
   qx::IxModel *pModel = new qx::QxModelService<customer_main_record, services::customer_main_record_services>;
   pModel->qxFetchAll_();
   engine.rootContext()->setContextProperty("customersModel", pModel);

This is wrong !
instead of qx::QxModelService<customer_main_record, services::customer_main_record_services>, you must use the class generated by QxEntityEditor !
It could explain why the Q_INVOKABLE function are not available in QML, because this is the wrong C++ type !

It should be something like this :
Code: Select all
   qx::IxModel *pModel = new customer_main_record_model();
   pModel->qxFetchAll_();
   engine.rootContext()->setContextProperty("customersModel", pModel);
Attachments
qxBlogModelView.zip
(107.97 KiB) Downloaded 441 times
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Thu May 05, 2016 10:27 am

(I have edited/deleted my reply, in this post, please read below)
Last edited by SteveW on Thu May 05, 2016 2:55 pm, edited 1 time in total.
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Thu May 05, 2016 12:30 pm

As well as using QML/ModelView QxORM features, I have mentioned in some previous Help threads that our project is also a Client / Server QxORM project (with QxEE generated client/server services code).

So the code you suggested we use:

Code: Select all
   qx::IxModel *pModel = new customer_main_record_model();
   pModel->qxFetchAll_();
   engine.rootContext()->setContextProperty("customersModel", pModel);


Does not work (it asserts during FetchAll in getDatabaseByCurrThreadId as we have not connected to a local database and this is no suprise!) and we need to use the Client/Model service system for the FetchAll process to work.

So we have to use the Service class (as your Client/Server tutorial code demonstrate) to do the remote "fetchall"...

Code: Select all
   qx::IxModel *pModel = new qx::QxModelService<customer_main_record, services::customer_main_record_services>;
   pModel->qxFetchAll_();


So, if we must use the Service for the FetchAll call, what then do we use to pass into setContextProperty so the QML can access the correct type for Q_INVOKABLES to work?
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby qxorm » Thu May 05, 2016 8:14 pm

(I have edited/deleted my reply, in this post, please read below)

Please next time, create another topic : this one is quite long now and I think we resolved your initial issue : you used the wrong C++ class in the QML context : you used qx::QxModelService instead of the class generated by QxEntityEditor (which inherit from qx::QxModelService and add some Q_INVOKABLE methods to manage relationships).

So, if we must use the Service for the FetchAll call, what then do we use to pass into setContextProperty so the QML can access the correct type for Q_INVOKABLES to work?

In QxEntityEditor model/view export plugin settings, I think you kept the default setting, which inherits from qx::QxModel (so without client/server feature).
To have client/server feature, please select the qx::QxModelService template before exporting your project, as shown in attached screenshot.
Attachments
qxee_model_view_services_export.png
qxee_model_view_services_export.png (63.49 KiB) Viewed 7557 times
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Fri May 06, 2016 1:19 am

please select the qx::QxModelService template before exporting your project


Thanks for this second part of the answer, I think this will be the one that gets us moving now.

Sorry the thread went on for a long time (in number of days and posts!). Sometimes the hardest part of a problem is knowing which question needs to be asked, then the answer is simple. Because half of our model/view (the simple "roles") were were working ok through server/client service and return expected data with our existing generated code, I did not think to question if it had been generated wrong in the first place! (If nothing had worked at all, then this would have probably been a quicker problem to have isolated)

Anyway thanks again! I will (hopefully) confirm tomorrow all is good once the project has been rebuild again.
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

Re: Nested "role" possible in Model/View/QML?

Postby SteveW » Tue May 10, 2016 2:04 pm

Hi. Just to end the post...

As you confirmed nested "roles" are not possible (the original question/title of this thread!). secondly, the reason we could not access dependant model data via it's Q_INVOKABLE name was due to the fact I had generated the QxEE Model code from Default instead of QxModelService.

Thanks again for getting us past our problems.
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

PreviousNext

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 10 guests