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

Forum for posting problems using QxOrm library

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

Postby qxorm » Tue May 03, 2016 11:47 am

It seems the problem is that "cmr_default_cad_id" is returning an integer, and is not "invokable" as a function ?

Yes, maybe the problem come from that the role has exactly the same name as the Q_INVOKABLE function (and QML engine doesn't do the difference and take into account only the role).
To confirm that, could you try to rename the Q_INVOKABLE function please ?

Note : you should not have the problem with 1-n relationship, because there is no role defined in this case.

Is it possible I missing some compiler definitions in the build somewhere?

No I don't think so : I think the problem is that the role name == the Q_INVOKABLE function name.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

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

Postby SteveW » Tue May 03, 2016 11:57 am

Hi

OK, I manually changed the .H file and the .CPP function name in the model class...

Code: Select all
   Q_INVOKABLE QObject * cmr_default_cad(int row, bool bLoadFromDatabase = false, const QString & sAppendRelations = QString());


Code: Select all
QObject * customer_main_record_model::cmr_default_cad(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)


But now the QLM errors

Code: Select all
qrc:/pages/customersPage.qml:56: ReferenceError: cmr_default_cad is not defined



Where else needs changing? Or must I modify the QxEE schema somehow and re-generate all the code?
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

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

Postby qxorm » Tue May 03, 2016 12:01 pm

Where else needs changing? Or must I modify the QxEE schema somehow and re-generate all the code?

Nothing else. And you don't have to regenerate something.

You just have to build your changes and the cmr_default_cad() function should be accessible in QML.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

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

Postby SteveW » Tue May 03, 2016 12:28 pm

Ok for whatever reason it wasn't available.

I've triggered full rebuild of the project (visual studio only did partial build of the model .DLL for my changes). I will get back to you with results once I have that ready.

WIll this mean a QxEE fix if we prove the bug? ie make "QxEE" call it "object_of_xxxxx" to avoid name clashes perhaps?
SteveW
 
Posts: 53
Joined: Tue Jan 19, 2016 4:12 pm

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

Postby qxorm » Tue May 03, 2016 12:33 pm

WIll this mean a QxEE fix if we prove the bug? ie make "QxEE" call it "object_of_xxxxx" to avoid name clashes perhaps?

Yes of course : if there is a conflict name issue, then we will provide a new QxEntityEditor version with a fix.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

ML

Postby SteveW » Tue May 03, 2016 8:02 pm

Hi,

I did a complete rebuild of the project after changing the .H and the .CPP to rename "cmr_default_cad_id" function to "cmr_default_cad", but still the following QML:

Code: Select all
            Text {
               id: updateText
               text: "Address 1 = " + cmr_default_cad(0).cad_address_1
            }


Gives the debug output error:

Code: Select all
qrc:/pages/customersPage.qml:38: ReferenceError: cmr_default_cad is not defined


So I don't think its enough to simply change those definitions on the model class to rename the function for QML access?
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 7:45 am

Yes, for me the rebuild was not necessary.

I will try to test on my side with the qxBlogModelView sample project of QxOrm package.
Then, I will get back to you with :
- is there a conflict name issue (role name == Q_INVOKABLE function name) with 1-1 and n-1 relationship ;
- I will improve the qxBlogModelView sample project, so you will have an example to work with QML and relationship ;
- I will improve the documentation too to show some examples...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

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

Postby qxorm » Wed May 04, 2016 11:01 am

I did some tests with qxBlogModelView sample project :

is there a conflict name issue (role name == Q_INVOKABLE function name) with 1-1 and n-1 relationship

No : you can have role name == Q_INVOKABLE function name : QML engine is able to get the correct object/function (so no need to change QxEntityEditor).

The difference is :
- to get the role value, you don't have to prefix by the model name instance ;
- to call the Q_INVOKABLE function, you have to prefix by the model name instance.

For example, in my case, my root model is a blog model (named myModel), and I have a n-1 (similar to 1-1) relationship to author, so I have a author_id role and a author_id() Q_INVOKABLE function. To get the author name, I can write :
Code: Select all
Text { text: "author: " + myModel.author_id(0).getModelValue(0, "name") }


Using the author id role name (so no prefix by the model name instance), I write (which gives the row id in database of the author) :
Code: Select all
Text { text: "author: " + author_id }


Another way to get the author name is to pass the author child model to another QML component, like this (in my case the other component is a ListView but you can use what you want) :
Code: Select all
ListView {
   model: myModel.author_id(0)
   delegate: Row {
      Text { text: "author: " + name }
   }
}


So in your case, to get the address, you should write :
Code: Select all
            Text {
               id: updateText
               text: "Address 1 = " + customersModel.cmr_default_cad_id(0).getModelValue(0, "cad_address_1")
            }

Or passing the address child model to another QML component, something like this :
Code: Select all
         ListView {
            model: customersModel.cmr_default_cad_id(0)
            delegate: Row {
               Text { text: "address: " + cad_address_1 }
            }
         }


Could you try that please and let me know if it is working fine ?
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 12:11 pm

Hi,

Unfortunately it is still not working here....

I will list the combinations:

First my List view is always set-up like this

Code: Select all
      ListView {
        id: customerAddressView
        anchors.fill: parent
        model: customersModel
      delegate: customersAddressDelegate
      }


So in my delegate I tried:

Code: Select all
               text: "Address 1 = " + cmr_default_cad_id


This lists the databases IDs ok. Proves I am talking to the model.

Next I tried your suggestion

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


This gives the error

Code: Select all
Property 'cmr_default_cad_id' of object qx::IxModel(0x61e8398) is not a function


If I go back to the old method I was trying to use (ie without parent modem prefix)

Code: Select all
cmr_default_cad_id(0).getModelValue(0, "cad_address_1")


I get the error:

Code: Select all
Property 'cmr_default_cad_id' of object [object Object] is not a function


So there is a difference in the error messages between " [qx::IxModel(0x61e8398)]" vs "[object Object]". Is this significant?

And finally if I modelName prefix ahead of the simple id...

Code: Select all
text: "Address = " + customersModel.cmr_default_cad_id


I get no errors, but the text in the list box = "Address = undefined"

Does any of that help diagone my issue?

Some extra information:

In my main.CPP, i have registered the types as follows:

Code: Select all
   qmlRegisterType<qx::QxModelService<customer_main_record, services::customer_main_record_services>>("uk.co.customer_main_record_model", 1, 0, "CustomersModel");
   qmlRegisterType<qx::QxModelService<contact_address, services::contact_address_services>>("uk.co.contact_address_model", 1, 0, "ContactAddress");


And at the top my of my QML, I have imported the model with import lines

Code: Select all
import uk.co.customer_main_record_model 1.0
import uk.co.contact_address_model 1.0
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 12:43 pm

FYI, I also have just attempted a different approach from the .CPP

And tried

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


To register the model and pre-populate before QML starts, but I get exactly the same combination of errors/results as above.
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

cron