Datamodel defined as context property

Code is:

theObject * robject = qobject_cast(qvariant_cast(dataModel->data(QVariantList() << i)));

     for(int x = 0; x < robject->metaObject()->propertyCount(); ++x) {
     context->setContextProperty(robject->metaObject()->property(x).name(), robject->metaObject()->property(x).read(robject));
    }

This method works for everything that is defined by default as a QVariant (for example QStringList / QString etc...).

The definition of the property is as follows:

    Q_PROPERTY(int count READ count CONSTANT)

    Q_PROPERTY(bb::cascades::DataModel* imageModel READ imageModel CONSTANT)

However if the metaObject() value-> property () .read () to debug, then she returns the following:

Debug: count
Debug: QVariant(int, 4)
Debug: imageModel
Debug: QVariant(bb::cascades::DataModel*, )

If I have a QML archiving I can access the count property, but the property imageModel is set to null. I know for what is is not null. What have I done wrong?

Having now made up my mind it for a while and returned that I realize what I was doing was completely ridiculous.

I loosely followed https://github.com/blackberry/Cascades-Samples/tree/master/repeater

I was doing an iteration through all properties and configure them separately. However, the best way to do is just to expose the object of the QML, exposing all the properties.

So all I had to do was:

context->setContextProperty("RepeaterData", robject);

Then in QML I can access each property as RepeaterData.* * etc...

Bravo for the help guys. Sorted!

Tags: BlackBerry Developers

Similar Questions

  • Accessing the context property of main.qml to a custom list in a file item separate qml

    Hi all

    Sorry if this is already covered somewhere.

    I currently have an application with a list view in my main.qml.  I put a context property for my class app c ++ to be "app" in my main.qml.  My list uses a custom list item that is defined in a file separate qml.  The custom list item has a popup menu.  In this context menu, I want to call Q_INVOKABLE functions that are part of my class from the main application in C++.  What is the best way to be able to do?  Should I just set the context property on my file qml of list item custom like I do with my main.qml or is there a better way?

    Thank you

    I think that this has been repeated several times, but as it is not really intuitive:
    a listitemcomponent lies in a different context, it cannot access the context property of the qml file.
    You can use the reference to the listview to reach outside, see https://developer.blackberry.com/cascades/reference/bb__cascades__listview.html ListItem.view

  • Cannot use the context property in a page created from an another qml with createObject()

                        gestureHandlers: [
    
                            TapHandler {
    
                                onTapped: {
                                    var page = infoPage.createObject();
                                    taskCont.ListItem.view.pushNewPage(page); //this pushes page to navigationPane (function at top of qml)
    
                                }
    
                                attachedObjects: ComponentDefinition {
                                    id: infoPage;
                                    source: "asset:///taskInfo.qml"
                                }
                            }
                        ]
    

    This is how I created the page of 'taskInfo. In the PRC, I registered a context property that I am able to access it from the current page but not in 'taskinfo. "gestureHandlers: []" is "listItemComponents".

    I expect to access the object of 'taskInfo' is because I am able to access it from another page created the same way.

    Here's how to register the context property.

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    
    mainModel = new ListModel();
    qml->setContextProperty("Model" , mainModel);
    

    OK, I found my problem.

    The reason why he doestn can't work because the page is pushed out "main.qml".

    This is part of my main.qml

    Container {
                id: main_content
    
                TaskList {
                }
    
            }
    

    TaksList is another qml file. When I createObject from this qml file, somewhy context property is not trafered to this object.

    I've found a workaround. I created a function in main.qml and only now I create object, so the contextproperty is transferred

  • Can not access the context property of the Interior of the ListView checkbox - onCheckedChange event

    I have a context property called "app" that connects to my C++ application. My listview has a box with onCheckedChange event listener. In this method, when I make a call to the C++ side. application app.runAction, the system displays not found error app.

    If I move the box outside the list view, it will correctly trigger app.runAction.

    Can you please take a look? Thank you!

    On the side of C++ on how I set the context property.

    QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);

    If (qml-> {hasErrors())}
    Returns false;
    }

    QML-> setContextProperty ("app", this);

    navigationPane = qml-> createRootObject();
    If (! navigationPane) {}
    Returns false;
    }

    QML side

     

    NavigationPane {}
    ID: nav

    {Page}
    ID: mainPage
    {Of container

    {To ListView

    listItemComponents:]
    {ListItemComponent}
    type: 'point '.
    {Of container

    Checkbox {}
    Determine whether the check box should be checked
    According to a value in the data model
    checked: ListItemData.checked
    onCheckedChanged: {}
    app.testAction ();
    }
    }

    This is a scope issue... I really hope the devs find a way to fix it properly apart from this ugly solution:

    You can solve this problem by setting your app variable in the global object Qt

    NavigationPane {
        id: nav
    
    onCreationCompleted: Qt.app = app
    
    Page {
            id: mainPage
            Container {
    ListView {
    listItemComponents: [
            ListItemComponent {
                            type: "item"
                            Container {
                       CheckBox {
                                    // Determine whether the CheckBox should be checked
                                    // according to a value in the data model
                                    checked: ListItemData.checked
                                    onCheckedChanged: {
                                         app.testAction();
                                         Qt.app.testAction();
                                    }
                                }
    

    all code in a ListItemComponent will suffer from this 'framing' question

  • conditionally define "BOLD" display property only one element on the page

    How can you conditionally set a display only point in bold.

    I can set the attribute of the HTML form element: style = "' make-weight: bold" "

    But I want to put it under certain conditions. Has been able to set the color under the condition with below the syntax before the process of page footer:

    HTP. PRN ("< script > $x("P102502_CTS025MT07").style.color = $x("P102502_HIDDEN_COLOR").value; (< /script > ');

    But can't figure out how to set the "BOLD".

    I tried htp.prn ("< script > $x("P102502_CTS025MT07").style.font - weight =" BOLD ";) (< /script > ');

    Cannot find the correct syntax for this.

    Hi pam499057,

    pam499057 wrote:

    How can you conditionally set a display only point in bold.

    I can set the attribute of the HTML form element: style = "' make-weight: bold" "

    But I want to put it under certain conditions. Has been able to set the color under the condition with below the syntax before the process of page footer:

    HTP. PRN(' ') ;

    But can't figure out how to set the "BOLD".

    I tried htp.prn(' ');

    Cannot find the correct syntax for this.

    What condition are you talking about? It's an event to an element for example "onchange" or "onload event page"?

    You can create a dynamic action on your event and the State that executes javascript defining the appropriate CSS code. For example your javascript code for the dynamic action can be (use ONE of the following):

    • If you want to that APEX javascript API old syntax:
    $x("P102502_CTS025MT07").style.color= $x("P102502_HIDDEN_COLOR").value;
    $x("P102502_CTS025MT07").style.fontWeight= bold;
    

    In javascript syntax code font is defined as follows: HTML DOM Style fontWeight property

    You will get the APEX API javascript here: http://docs.oracle.com/cd/E37097_01/doc.42/e35127/javascript_api.htm#AEAPI266

    • If you want to APEX new javascript API (which is based on jQuery) syntax:
    var clr = apex.item("P102502_HIDDEN_COLOR").getValue();
    apex.item("P102502_CTS025MT07").setStyle("color", clr);
    apex.item("P102502_CTS025MT07").setStyle("font-weight","bold");
    

    The new javascript API for APEX is documented here: http://docs.oracle.com/cd/E37097_01/doc.42/e35127/javascript_api.htm#AEAPI29446

    • If you want syntax pure jQuery:
    var clr = $("#P102502_HIDDEN_COLOR").val();
    $("#P102502_CTS025MT07").css("color",clr);
    $("#P102502_CTS025MT07").css("font-weight","bold");
    

    NOTE: In the answer above by Sunil he mixed the jQuery and javascript of APEX syntax, therefore, it will not work.

    • If you want that more compact jQuery syntax:
    var clr = $("#P102502_HIDDEN_COLOR").val();
    $("#P102502_CTS025MT07").css({ "color": clr, "font-weight": "bold" });
    

    Also the solution given by Jitendra will be static, that it will not apply CSS under certain conditions.

    Finally, it is not advisable to use HTP. PRN to emit javascript, because it is intended more to dynamic HTML issue. The dynamic action is an option more appropriate in this context.

    I hope this helps!

    Kind regards

    Kiran

  • GroupDataModel in an active Frame (aka Cover)?

    Hey guys,.

    I have an active frame for my application that uses a simple ActiveFrame class (derived from examples on the ' net).  He received an ImageView and a label.  in my main.qml I connect the signal of thumbnail() to an onThumbnail() function and send the text to the ActiveFrame class to update the label by a Q_INVOKABLE update() method.   Everything works beautifully.

    I would replace the label with a ListItemView that is attached to a GroupDataModel in my main class (a class of client Manager 'work').

    How can I go on the passage of the GroupDataModel to the SceneCover?

    the job manager and the scene covers both are exposed to QML via setContextProperty.

    Can I put a GroupDataModel as a property on my SceneCover and set it with a Set accessor method?

    is there a better way to do it?

    EDIT: update, I tried simply adding a ListItemView to the SceneCover.qml page and some properties Label.text of binding to the property of the presentation object workManager representing the GroupDataModel, but the ListItemView on the SceneCover is empty.

    Thank you!

    J

    OK, solved it myself.

    First of all, in the applicationui.cpp file, I put the parent to my WorkManager object and the SceneCover object:

        // Create a WorkManager
        WorkManager * workManager = new WorkManager(this);
        qml->setContextProperty("workManager", workManager);
    
        // Active Frame
        ActiveFrame * activeFrame = new ActiveFrame(this);
        Application::instance()->setCover(activeFrame);
        qml->setContextProperty("activeFrame", activeFrame);
    

    Then, in the constructor for the class ActiveFrame, I find the WorkManager and define a context property.

        qDebug() << "ActiveFrame;:ActiveFrame(), my parent is " << parent;
        wm = parent->findChild("myWorkManager");    QmlDocument *qml = QmlDocument::create("asset:///SceneCover.qml")
                .parent(parent);
        Container *mainContainer = qml->createRootObject();
        setContent(mainContainer);    qml->setContextProperty("myWorkMgr", wm);
    

    After having done that, I can access properties, in particular, the GroupDataModel property of the WorkManager.

    not sure if it's the "right" way to do it, but it seems to work reliably.

    see you soon,

    J

  • ListView Access of ListItemComponent context action onTriggered model

    Consider following piece of code:

                ListView {
                    id: listView
                    dataModel: model
                    listItemComponents: ListItemComponent {
                        content: StandardListItem {
                            title: ListItemData.name
                            contextActions: ActionSet {
                                actions: ActionItem {
                                    title: "Delete"
    
                                    onTriggered: {
                                        //ListItem.view.model .... doesn't work
                                    }
                                }
                            }
                        }
                    }
                 }
            }
    

    When the user chooses to delete a line, I would like to access the listview model and remove the line given. But I can't get my hands on the model (as it is now defined as attached property).

    Docs say:

    ListItem.view - The ListView in which this item is visible. The item is in a context separate from the ListView, so any symbols from the ListView context that are to be accessible from items must be placed as dynamic properties on the ListView
    

    But to be honest I don't understand what I need to do to make it work (ie. have access to the parent listView.

    Any help would be greatly appreciated.

    Oh, I would do this without falling back into C++ code. I know how to solve this problem with c ++.

    Thank you

    You must reference it in your ListItemComponent ListItem:

    myItem.ListItem.view.dataModel
    
  • Created in the ListView lost when C++ ListItem custome context reference

    Hi all

    I have a listview that generates a list of the custome listviewItems (ie the containers). Containers have a setContextProperty to my database object. But when they are added to the list view, I can't access the database context property. I realize that the listview is not in the same context as the page but I don't understand why when I bind context for the real item the reference he lost?

    Error: asset:///WorkoutListItem.qml:17: ReferenceError: can't find variable: _Dal

    List.QML

    
    Page
    {
    Container { ListView { id: workoutList horizontalAlignment: HorizontalAlignment.Fill
    
     dataModel: _Dal.ListofWorkouts listItemComponents: [ ListItemComponent {  type: "item" WorkoutListItem { workoutId: ListItemData.id workoutName: ListItemData.name } } ] }//End List }//End root
    }//EndPage
     
    

    WorkoutListItem.qml

    
    Container { id:root property int workoutId: -1 property variant workoutName: ""
    
     layout: StackLayout { orientation: LayoutOrientation.LeftToRight }
    
     Button { id: workoutDelete text: "Delete" onClicked: { var result = _Dal.DeleteWorkout(root.workoutId) } }
    
     Label { id: workoutNumberLabel text: root.workoutId }
    
     Label { id: workoutNameLabel text: root.workoutName }
    
     Button { id: workoutEdit text: "Edit" onClicked: { //TODO: Open workout page } }}
     
    

    application.cpp

    
    QmlDocument *WorkoutListItem = QmlDocument::create("asset:///WorkoutListItem.qml").parent(this);
    WorkoutListItem->setContextProperty("_Dal", dal);
    

    Thanks in advance for any help

    -J

    itemRoot.ListItem.view.yourFunction(ListItemData)
    

    yourFunction (data) is defined in the ListView itself

    from there, you have access to your context

  • How can I respond to the signals of the QML context properties?

    I put a property will involve on my .cpp, so I can access it on my document QML.

    How I respond to the signals defined in this context property class?

    Hello

    You can connect signals to help
    contextName.signalName.connect (javascriptFunction);
    to disconnect:
    contextName.signalName.disconnect (javascriptFunction);

    Or use the {} QtQuick connections for automatic connection / disconnection:

    http://supportforums.BlackBerry.com/T5/Cascades-development/QML-connections-element/m-p/2063301#M955...

    http://supportforums.BlackBerry.com/T5/Cascades-development/notify-QML-from-another-class/m-p/196254...

  • Property with table input node

    Hello

    I have a table, and I would get the unique values. Then I would put the unique values as input

    my digital order. On the diagram below, the user should be able to choose the following numbers:

    1,2,3,5,7; given that th is the unique values

    In a Word, is it possible to place a digital control of irregularly spaced numbers.

    If the above is not possible, can you pass the unique values of a ring of menu rather

    A digital control accepts only a single value. You can not he contain several values.

    If the above is not possible, can you pass the unique values of a ring of menu rather

    You can define the Strings property of [] of the ring menu to your list of values:

  • To access the properties of QML context through several QML files

    It seems so basic, but I don't see how well...

    I put a 'WebAPI' context property to access my class that makes HTTP requests etc. WebAPI works very well main.qml, but when I try and use it in the included LargeThumbItem.qml I get:

    "LargeThumbItem.qml:37: ReferenceError: can't find variable: WebAPI.

    How to set a context property that is available for * all * my QML files? What is the best practice for this?

    hand. QML

    {

    ...

    {ListItemComponent}

    type: 'point '.

    LargeThumbItem {

    }

    }

    ....

    }

    LargeThumbItem.qml

    {

    ....

    WebAPI.getImagePath (...)

    ...

    }

    I do the usual configuration...

    QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);

    QML-> setContextProperty ("WebAPI", m_pWebAPI);

    I tried calling qml-> documentContext()-> setContextProperty(), but it did not work. Is there a global context that I can put all documents will inherit? (the API documentation seems to suggest there is).

    This problem is related to what is described here and the solution is the same. The problem is that the ListItemComponents have a different context and lifecylce due to the fact that they are cached in and out as the scrolls of the ListView (see here for details).

    I solved it by adding a dynamic property on the global object of 'Qt' for example in onCreationCompleted() or anywhere where the senses in main.qml. In my case, I chose to pass a string, because I don't know if the global property to the instance around WebAPI is a good idea.

    Qt.homeListBaseURL = WebAPI.getImagePath ("TitleImagePathPrefix", "170 x 240")

    Then in LargeThumbItem.qml for example

    {WebImageView}

    ...

    URL: Qt.homeListBaseURL + ListItemData.ContentId + '.jpg '.

    ...

    }

  • Custom property syntax model

    Hello

    JDev 11.1.2.4

    I defined a custom property for one of my VO attribute. The property is called specialLabel.

    For example if I want to access this property, I can write #{bindings. MyAttribute.hints.specialLabel} and it does not work as expected.

    But now I want to use it in an af:column headerText property

    The syntax generated for a column is links. MyView1.hints.MyAttribute.label. I tried links. MyView1.hints.MyAttribute.hints.specialLabel access to the custom property, but it does not work.

    What is the correct syntax?

    Thank you

    Which are different objects, in the first case of 'tips' belongs to the attribute in the second case to VO and VO.

    You can probably add MyAttribute pageDef and use #{bindings. MyAttribute.hints.specialLabel} as column label.

    Dario

  • Property of hierarchy DRM: EPMA. SharedDimension - how to get it filled with the values?

    We have a hierarchy of DRM, we want to push to a Dimension of sharing EPMA. In DRM, selecting the hierarchy and by changing the 'Dimension' shared property, the drop-down list box previously had values in there (some have been our shared Dimensions EPMA, but several us not the Shared Dimensions) but no longer has any selectable values. How do we get DRM to sort the list of the Shared Dimensions of our EPMA instance in the drop-down list of properties shared Dimension?

    Hello

    I could be wrong completely here, but that's what I discovered trying to look for EPMA. Property of SharedDimension.

    This property gives me drop-down list without having to do anything and the drop down menu is the list of groups available in hierarchy, but if I'm putting some values manually in the definition of ownership--> the list of values is not showing me all the values (list of groups of hierarchies and not the value created manually) in the drop-down list.

    I think that this property will not take a different list than list of group hierarchy as the Data Type defined for that property in the model of the APP is "Group of the hierarchy". Once again this property is used in the export "EPMA. E.M.P. architect Shared Library"to penetrate the hierarchies EPMA Shared Library.

    Then you can try to see if all values are entered in the definition of the property--> list and try to delete it OR to check if the required groups in the hierarchy are created in consequence.

    Let me know if it helps

    Thank you

    TFDC

  • Call the procedure to set the context before interactive report refreshes the data

    Hi guys,.

    I have a question mind an interactive report which takes the data in a view.

    The problem is that whenever I take the data from the database I need to define a context (user name and password) before running the query so the view will be taken into account the context and return only the lines that I have access.

    Everything works fine when I'm first loading of the page: I have first to define the context, then load all the data I need on the page, including the IR. But when I try to apply IR filters, or even don't go to the next page no data is returned. I believe this happens because the context is not defined before the execution of the query to load the data and I don't seem to find a way to put it.

    I tried to add a dynamic action on some events on IR (change, clicking, etc.) that executes the procedure to set the context, but without success - even if the event is raised, the report still doesn't return any data.

    Can someone help me with this issue please?

    Florin

    Use the attributes of application security Code PL/SQL of the initialization/cleanup of the database Session to do this: http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/bldr_attr.htm#HTMDB28929

  • Bug: mayhem suddenly unleashed on adding a custom modules property

    Structure of the project:

    Project A project B and C in the form of modules project references.

    Project B and project reference project in the form of module C.

    Project D is just public the names of the files only - no rules.

    Everything seems to work fine until... Add a field to a custom property on an attribute in the project B or C.

    Then trying to build the project, the compiler throws an OPA-E00285 for each attribute in the project.

    The errors come floods only after the addition of a custom property and as a result of that.  I completely 100% verified with control of source diff.

    Expected result: custom properties do not change the behavior of the compiler in this way.

    Adding a custom property to the imported attributes of the module D means that modules B and C now have different definitions of these attributes.  It is a problem of project since it does not know which definition to use - the one with the custom property or the one without the custom property.  Define the custom property in the module D.

Maybe you are looking for