Access QML QList

I recover a QList from 2 of the objects in the database and you want to access in QML.

To do this, I registered the type:

qmlRegisterType("com.class2", 1, 0, "Class2");

In addition, my class of database is published in qml:

qml->setContextProperty("persistanceService", persistenceService);

It's the method definition:

Q_INVOKABLE
QList getClass2List();

In my qml I use import to put at the disposal of the registered type:

import com.class2 1.0

This is the code to access the QList:

onCreationCompleted: {
  var class2list = persistanceService.getClass2List();
  console.log("retrieved "+class2list .length+" elements");
}

And I get:

TypeError: Result of expression 'class2list' [undefined] is not an object.

QList and other more dynamic classes are not really used in QML. There is something called QDeclarativeListProperty, but that allows to display the list. Then access you the similar elements in a table as myobj [1]. It also has the County and a few other helper methods.

http://Qt-project.org/wiki/How_to_expose_lists_to_QML

Tags: BlackBerry Developers

Similar Questions

  • Components of access QML in c ++ with navigationpane

    I used the code works like a charm, but I want to access the user interface below the elements that are present in the item Page how do I am getting the below but the application breaks down

    I have a NavigationPane in file c ++ and the page must be pushed after the button is clicked.

    QmlDocument *qml = QmlDocument::create("asset:///SearchResults.qml").parent(this);
        qml->setContextProperty("peoplefinder", this);
    
        Page *mypage = qml->createRootObject();
        qml->setParent(mypage);
    
        ActivityIndicator *myindicator = qml->findChild("myIndicator");
        qDebug()  << myindicator->isVisible();
    
        mNavigator->push(mypage);
    

    Please help me how do I tried access also the child ActivityIndicator through my object page but am unable to do so.

    its page-> findChild<>() and not-> findChild qml

  • How access QML label creator no - QML C++ file

    Subject: C++ see the variable screen QML.

    Error: Don't know how to do it.

    Question: How do I access the QML file creator no - QML C++ labels?

    or,

    Not any related example or document API that I can read?

    Mini code:

    A C++ file to create QML

    ApplicationUI::ApplicationUI (bb::cascades:Application * app)
    : QObject (app)
    {
    QML = QmlDocument::create("asset:///main.qml").parent(this);

    root = qml-> createRootObject();
    App-> setScene (root);

    }

    Another C++ to show a QML screen variable.

    Sensor:ensor (bb::cascades:Application * app)
    : QObject (app)
    {

    VideoLabel = root->findChild ("videolabelname");
    VideoLabel-> setProperty ("text", "2");
    }

    Thank you for your attention,

    Thanks Pierre. I've read before, but not any idea for the issue.

    I found a useful sample code.

    https://developer.BlackBerry.com/Cascades/documentation/dev/integrating_cpp_qml/custom_control_tutor...

    I have a solution to access label creator non - C++ file QML QML made the sample.

    The key's value and setvalue().

    Mini code for the solution:

    CPP.

    int sensor: value()
    {
    Return m_iValue;
    }

    Sub Sensor::setValue (int i)
    {
    name is the same as an instruction HPP WRITE Q_PROPERTY
    m_iValue = i;
    issue of valueChanged (m_iValue);
    }

    HPP.

    Q_PROPERTY (int value READ WRITE setValue NOTIFY valueChanged)
    public:

    Sensor();
    Virtual ~ Sensor() {}
    QObject * videolabel;
    Q_INVOKABLE
    int value();
    void setValue (int i);

    signals:
    void valueChanged (int);

    private:
    int m_iValue;

    QML:

    Button {}
    ID: aButton
    text: _app.value
    onClicked: {}
    _APP.ValueChanged.connect (aButton.onValueChanged);
    _APP.value = _app.value + 1;
    }
    onValueChanged (val) {} function
    aButton.text = "new value:"+ val;»
    }
    }

  • Access QML in C++ label

    Hello

    I wonder how I can access a label I have in a QML in C++ file. Previously, I had the main.qml label and was able to get that way:

    hand. QML

    property alias currTimeText: currTime.text
    

    c ++

    mRoot->setProperty("currTimeText", timeString);
    

    However, I restructured my qml so that the label is no longer inside main.qml. Now main.qml has a button that pushes a page in another qml file and contains my label. What makes the problem more complex. Note that in the c ++ code above mRoot is created from main.qml. Any help is appreciated!

    Thank you

    Gerry

    If you want to access an object of c ++ assign an object name

    Label{
        id:labelid
        objectName:"labelname"
        text: "text"
    }
    

    So from c ++

    You can find and access the object directly using

        mNavPane = qml->createRootObject();    Label *label = mNavePane->findChild("objectName");label->setText(labelText);
    
  • How to access QML object to display the error message.

    Hi all

    I have a request. I got a login screen ("asset:///qml/screenLogin.qml"). "Connect" OB button I click sendt asks the server sending the XML data as a response.

    After that, I am parsing the XML data by using Connection Manager. Code is below:

    /*
     * LoginHandler.cpp
     *
     *  Created on: Jan 15, 2013
     *      Author: Ekansh
     */
    
    /*Parsing the Login Response Structure.
    
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    
     */
    
    //#include 
    #include "loginhandler.hpp"
    
    #include 
    #include 
    #include 
    #include 
    #include `
    #include 
    #include 
    
    namespace bb {
    namespace cascades {
    
    LoginHandler::LoginHandler() {
        // TODO Auto-generated constructor stub
    
    }
    
    LoginHandler::~LoginHandler() {
        // TODO Auto-generated destructor stub
    }
    
    bool LoginHandler::startDocument() {
        qDebug() << "Start of the document.";
        return true;
    }
    
    bool LoginHandler::endDocument() {
        qDebug() << "End of the document.";
        return true;
    }
    
    bool LoginHandler::startElement(const QString &namespaceURI,
            const QString &localName, const QString &qName,
            const QXmlAttributes &atts) {
        qDebug() << "Start of element" << qName;
        for (int i = 0; i < atts.length(); ++i)
            qDebug() << "  " << atts.qName(i) << "=" << atts.value(i);
    
        return true;
    }
    
    bool LoginHandler::endElement(const QString &namespaceURI,
            const QString &localName, const QString &qName) {
        qDebug() << "End of element" << qName;
    
        if (qName == "sessionid") {
            sessionid = tagValue;
            qDebug() << "sessionid:: " << sessionid;
        } else if (qName == "error") {
            error = tagValue;
            qDebug() << "error:: " << error;
    
            /*QmlDocument *qml = QmlDocument::create("asset:///qml/screenLogin.qml");
            //Container *root = qml->createRootObject();
            AbstractPane *root = qml->createRootObject();
            QObject *newLabel = root->findChild("errorObject");
    
            if (newLabel)
                newLabel->setProperty("text", "error");*/
    
        }
        return true;
    }
    
    bool LoginHandler::fatalError(const QXmlParseException & exception) {
        qWarning()
                << QString("Fatal error on line %1, column %2: %3").arg(
                        exception.lineNumber()).arg(exception.columnNumber()).arg(
                        exception.message());
    
        return false;
    }
    
    bool LoginHandler::characters(const QString &str) {
        qDebug() << "Characters" << str;
        tagValue = str;
        return true;
    }
    } /* namespace cascades */
    } /* namespace bb */
    

    When I put the wrong credentials, I want an error message to display on login QML.

    See the code in the EndElement this handler method.

    But I am not able set the error message when the connection QML.

    Help, please.

    You can set the label with the message as below. Condition that you specified label with the same "errorLbl" objectname qml

    QObject *lblError = bb::cascades::Application::instance()->findChild("errorLbl");
        if (lblError)
            lblError->setProperty("text", "error");
    

    -Dishooom

    I hope this helps...

  • Can't push to the navigation of a component outside the main.qml pane

    Here's some of my main.qml

     Container {
                id: main_content
    
                attachedObjects: [
    
                    ComponentDefinition {
                        id: listtodo
                        source: "mainList.qml"
                    }
                ]
    
                property variant listtodoObj
    
                onCreationCompleted: {
                    listtodoObj = listtodo.createObject();
                    if (!listtodoObj)
                        listtodoObj = listtodo.createObject();
    
                    listtodoObj.dataModel = Model.get();
                    main_content.add(listtodoObj);
                }   
    
            }
    

    I have not included of NavigationPane, but in the hand, I have a pane of navigation with the id "navigationPane.

    Here's the part of my mainList.qml:

    gestureHandlers: [
    
                        TapHandler {
    
                            attachedObjects: ComponentDefinition {
                                id: infoPage;
                                source: "asset:///taskInfo.qml"
                            }
    
                            onTapped: {
    
                                var page = infoPage.createObject();
    
                                navigationPage.push(page);                     
    
                            }
                        }
                    ]
    

    But I can't access navigationPane. In the console it says: "cannot find variable: navigationPage.

    What can I do?

    This should help:
    http://supportforums.BlackBerry.com/T5/native-development-knowledge/how-to-access-QML-properties-fro...

  • call the function onCreationCompleted c ++ in qml

    I currently have a problem with the c function call ++ QML.

    Œuvres of normal calls. But when I call a function in onCreationCompleted, he cannot access qml object on the page.

    For example:

    {Page}

    onCreationComplete:

    {myFunction() ;}

    Button {}

    ojbectName: "button1".

    }

    }

    MyFunc access using findChild button1.

    But this return 0 x 0, means the button does not exist.

    So how do I access button1 in c ++ to what page is loaded?

    I have posted from a phone, so sorry if there is no error.

    Look, we can't access the qml object when the page is created (we call it in onCreationCompleted). I bypassed by calling the function after navigationpane.push.

  • findChild custom datamodel

    Hello

    I know how to recover a QML from C++ object. For example, if myObj is a component TextArea, I can change the text like this:

    QObject *obj = appPage->findChild("myObj");
    if (myObj){
        myObj->setProperty("text", "hello");
    }
    

    Now, I would get the DataModel for a ListView, which is a custon DataModel:

    ListView {
        dataModel: searchModel
    ...
    }
    
    attachedObjects: [
    
        SearchModel {
            id: searchModel
            jsonAssetPath: "app/native/assets/appsearch.json"
            filter: "All categories"
        }
    ]
    

    At least, my SearchModel has one public slot: void updateListWebviews (const QString text);

    I want to trigger the updateListWebviews slot in a function of the CPP. Could you help me to achieve this please?

    Thanks for your help,

    Laurent

    You can access 'qml objects' very well, behind the scenes, they are ordinary objects in c ++.

    You can call a qml method using QMetaObject::invokeMethod

    You can also connect a signal c ++ in qml and just send the signal to your user interface. I judge that the most elegant solution.

  • What is the best way to refresh one when its interface elements user is updated?

    I have a Page in a NavigationPane. I click on a button that is immediately disabled while I perform some behind the logic of 'scenes' (a little humor BB). After that I'm done, I would like to re - activate the button.  I found how I can modify the attributes in the code, but the screen remains the same.

    Basically, I have the same problem as this guy:

    http://StackOverflow.com/questions/12482464/cannot-access-QML-object-in-c-code

    I need to store a pointer to the application object, and continually call setScene? Do I always have to set the scene for the Navigation pane, since that's what I'm pushing my pages on?

    Is there a cleaner way to do this?

    Thanks again, guys.

    Well, that looks more like the real solution. How I would emit as a signal?

    I am a native Android and it is usually automatic. Could you show me a code snippet?

    Here are some of the code I use:

    Getting button:

    signInButton = getOwnedPage()-> findChild (SIGN_IN_BUTTON_OBJECT_NAME);

    Later...

    signInButton-> setEnabled (true);

    signInButton-> setProperty ("text", "wutwut");

    qDebug() < signinbutton-=""> text();

    signInButton-> setText ("hey now");

    qDebug() < signinbutton-=""> text();

    I have the debugs to prove that I'm actually changing the properties of this object, but it is not yet reflected on the screen.

  • Access a list of QObjects using Javascript of QML?

    I want to access a list of QObjects of Javascript so that they are accessible for example like this:

    var items = mycontextproperty.getItems()
    for(i =0; i< items.length; i++){
       items[i].name;
    }
    

    I expect fair access properties read-only.

    In C++, I have a what method defined like this

    Q_INVOKABLE QList getItems()

    or like this

    Q_INVOKABLE QVariantList getItems()

    and then I manually add QObject * to QVariantList

    Neither one seems to work. Does anyone know how to expose a simple list in C++ QML?

    I think that you can implement to get the stitch data of C++.

    var size = mycontextproperty.getItemSize()
    for(i =0; i< size; i++){
       //name = mycontextproperty.getItemName(i);    var data = mycontextproperty.getItem(i); //Should have a try with QVariantMap
    }
    
  • How Textfield text on another page qml property access

    Hello

    I started 10 BB development recently and need help. I searched this forum but could not find some information exactly related to my problem (unlike only), or I missed something from basically. My main.qml, I want to access the text property of the textfield of the InputControl.qml to be used as a parameter in my SQLQuery (attached object). I tried to use the fieldname method alias property, but it does not work. I can't feature outside. Here is my code:

    hand. QML

    import bb.cascades 1.4
    import bb.cascades.datamanager 1.2
    import bb.system 1.0
    import bb.data 1.0
    
    Page {
    
        id: root 
    
        titleBar: UIControls {
        }
    
        //! [0]
       content: Container {
    
            leftPadding: ui.du(2)
            rightPadding: ui.du(2)
            topPadding: ui.du(2)
            bottomPadding: ui.du(2)
    
            InputControl {
            }
    
            // The ListView that's used to display the artist data
            //! [1]
            ListView {
                id: myListView
    
                //property variant dq: defaultDataQuery
                // Associate the list view with the data model that's defined in the
                // attachedObjects list
                layout: StackListLayout {
                    headerMode: ListHeaderMode.Sticky
                }
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 1.0
                }
                horizontalAlignment: HorizontalAlignment.Fill
                verticalAlignment: VerticalAlignment.Fill
    
                listItemComponents: [
    
                    ListItemComponent {
                        type:  "item"
    
                        Container {
                            Label {
                                text: ListItemData.Japanisch
                                layoutProperties: StackLayoutProperties {
    
                                }
                                topMargin: 5.0
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Bold
                                    color: Color.create("#7a184a")
                                }
    
                            }
                            Label {
                                text: ListItemData.Lesung
                                textFit.maxFontSizeValue: 9.0
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Normal
                                    color: Color.create("#ff1818e9")
                                }
    
                            }
                            Label {
                                text: ListItemData.Deutsch
                                textStyle {
                                    base: SystemDefaults.TextStyles.TitleText
                                    fontWeight: FontWeight.Normal
                                }
    
                                multiline: true
                                textFit.maxFontSizeValue: 8.0
                            }
                            Divider {}
                        }// Container
                    }
                    // Use a standard list item to display the data in the model
                ]    
    
            } // end of ListView
    
        }//![1]
    
        attachedObjects: [
            //! [2]
            // One of the default provided DataModel's
    
            GroupDataModel {
                id: dataModel
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource
    
                // Load the data from an SQL database, based on a specific query
                source: "WadokuJT.db"
                //query: "select Japanisch, Deutsch, Lesung from WadokuJT where Deutsch like '%Wasser%'"
                query: "select Japanisch, Deutsch, Lesung from WadokuJT where Deutsch like '%" + stext + "%'";
    
                onDataLoaded: {
                    // After the data is loaded, insert it into the data model
                    dataModel.insertList(data);
    
                }
                type: DataSourceType.Sql
            } // end of DataSource      
    
        ]//! [2]  
    
        actions: [
            //! [8]
            ActionItem {
                title: qsTr("Search")
                imageSource: "asset:///images/ic_search.png"
                ActionBar.placement: ActionBarPlacement.Signature
                onTriggered: {
                    myListView.dataModel = null
                    dataSource.load()
                    //myListView.dq = defaultDataQuery
                    myListView.dataModel = dataModel 
    
                }
            },
    
            ActionItem {
                title: qsTr("Settings")
                imageSource: "asset:///images/ic_settings.png"
                onTriggered: {
    
                }
            },
    
            ActionItem {
                title: qsTr("Help")
                imageSource: "asset:///images/ic_help.png"
                onTriggered: {
    
                }
            }                           
    
        ]//![8]
    
    } // end of Page
    

    And here is my InputControl.qml

    import bb.cascades 1.4
    
     Container {
         property alias stext: txtSearchText.text
    
        Label {
            id: lblSearchText
            text: "Searchtext\r\n"
    
        }
    
        TextField {
            id: txtSearchText
            layoutProperties: FlowListLayoutProperties {
    
            }
            hintText: "Enter Searchtext"
        }
    }
    

    Any help is greatly appreciated. Thank you.

    Give InputControl an id (in main.qml), for example someId.

    Access the variable an alias like someId.stext

  • How to access controls QML custom in C++ code...?

    Hi all

    I create a custom dialog to display the loading popup and it successfully added in the QML code but I don't get way to access this dialog box in the code c ++ to close when the network connection is closed and the response is received from the web service.

    Here is my code:

    import bb.cascades 1.0
    
    Dialog {
        Container {
            preferredWidth: 400
            preferredHeight: 200
            background: Color.Black
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
            ActivityIndicator {
                id: loginIndicator
                objectName: "indicator"
                preferredWidth: 130
                preferredHeight: 130
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                onStopped: {
                    if (errorTextid.text.trim() == "") {
                        var blogpage = goToWebView.createObject();
                        navPane.push(blogpage);
                    }
                }
            }
            Label {
                text: "Please wait... Logging In"
            }
        } // Container
        onOpened: {
            // Reset the fire alarm since it is opened.
            loginIndicator.start()
        }
    
    }
    

    Please suggest something

    Concerning

    Thank you simon for show the way finally I got this problem resolved

    Solution for this problem is:

    Dialogue * popUpDialog =
    BB::cascades::application::instance()-> findChild ()
    "LoadingPop");
    popUpDialog-> close();

  • to access the QML attached objects in C++ and best practices for the handling of the user interface in classes

    Hello

    I have in fact 2 queries

    (1) how can we access attachedobjects defined in QML in C++?

    (2) I'm loving development on Blackberry 10 C++ is one of my favorites. But I'm a bit lost when it comes to managing the user interface in classes. For example when we create the project through momentics we have a class called ApplicationUI. It manages all the (default) user interface commands, we in C++. as for example creating the document qml and setting as root user interface, etc. I am now working on an app that have NavigationPane as root, and then I continue to push pages (like the screens). But now the code for all pages is inside my ApplicationUI. What is the best practice to keep the UI for each page logic in a separte C++ class?

    I also develop for Android that a separate class for each activity, this code does not mingle for each activity. Please guide me how can I keep logic of user interface of each Page into a separate class of C++?

    regarding your second question:
    I think this is the simplest approach to keep all things in the UI in QML. You can easily put things into separate files.

    If you want to use c ++ to the user interface: can be done, too. just put it in separate classes and include those in your application class.

  • To access the classes of CPP in qml.

    I have set up to access the classes of PCB in qml in two ways: -.

    1. create an attached object and the id of the class of CPP special and then access via the id.

    2. fix the CPP on the qml class before pushing the page using the setContextProperty.

    I wanted to know exactly when to use these two methods. There a difference in terms of scope and memory. Please explain.

    Great Question!

    Local objects:

    Attached to objects, or who inherit from classes of cascades, is the simplest way to expose c ++ objects that relate to user interface elements. This is what you use if you want this object to BELONG to this context qml. It is created by the qml context when createObject is called (your qml file is loaded) and destroyed with the user interface objects. You can create many of these objects, anywhere you need. However, if you want to expose global properties, it is probably not a good approach.

    The only time you would use objects attached to global stuff is if you expose a singleton class to allow qml set locations to manage signals (OrientationHandler is an example of that, without an OrientationHandler object, that you have nothing to connect).

    Global objects:

    Context properties can be considered global variables for a particular context, but with inheritance: context properties are passed to the contexts of the child. These objects are the PROPERTY of c ++, must be created before the creation of the object (createObject is called) and must remain valid for the lifetime of any context, they are placed in, but then destroyed is no longer necessary.

    The disadvantage of context properties changing them can be expensive. If you set a context property after the createObject call (that is to say an object exists that was created from this context), then all links in javascript in this context will be re-evaluated. However, you can mitigate this issue by exposing an object that contains the value as a property, so that links to branch on change of signals well if necessary.

    Inheritance is where shine context properties. There is a context root, which is in this context of default parent for new contexts. If you set a context property of the root context, it is available everywhere in any document qml. Here is an example of how do:

    QmlDocument::defaultDeclarativeEngine()->rootContext()->setContextProperty("app", myApp);
    

    Note: when I speak of createObject, I'm talking about QDeclarativeContext::createObject. It is called internally by QmlDocument::createRootObject.

    For more information on the Qml contexts, see http://qt-project.org/doc/qt-4.8/qdeclarativecontext.html

    For more information about the inner workings of qtdeclarative, see http://qt-project.org/doc/qt-4.8/qdeclarativeengine.html and http://qt-project.org/doc/qt-4.8/qdeclarativecomponent.html

    http://Qt-project.org/doc/Qt-4.8/qtbinding.html is still relevant as well

  • How to access the properties of the ListItemComponent Page in QML

    Hello

    I'm new to BB10 development. I need help for the problem mentioned (in red) below

    {Page}

    ID: page

    property storage storage / / this is a C++ class that is registered for access from pages QML

    {Of container

    {To ListView

    listItemComponents: {ListItemComponent}

    {CustomListItem}

    ImageButton {}

    text: "Save."

    onClicked: {}

    Storage.Save)

    I am not able to get the reference of the storage property defined in the Page. It is always [NULL], I get the mention very well outside the ListView

    }}}}}}

    PS: I only provided the necessary code

    I found the solution

    added CustomListItem id as

    ID: customCell

    now

    customCell.ListView.view.parent.parent.storage

Maybe you are looking for