Help in QML

Hello

I am very new QML and no experience in C++ based application.

Need help from the experts on this forum

I am building a simple application that has shape and a results page.

the QML for two pages is complete.

Now, I want to know how I can extract data from the slim form-function and calculate the resulting data and fill my second screen.

I don't know how to get my requirement here, then posting this request.

If I can get QML based approach that would be better, but C++ approach is also welcomed.

Thank you

Afonso Tyagi

To do this is to create a property or an alias property to the value that you want to fill on the second page.

Then in your main QML, you can do something like this... (Example NavigationPane)

var page = secondPageDefinition.createObject();
page.propertyToPopulate = someCalculatedValue
navigationPane.push(page)

Tags: BlackBerry Developers

Similar Questions

  • Help C++ QML

    Hello, I am very new to C++ / QML development (I'm familiar with JAVA).

    I try the simplest thing, create a named factorial function that takes a parameter (hard-coded) which displays the result on the screen when the application starts and displays the screen.  Here is my code, please explain what I'm doing wrong.  I'm not clear how everything together "fits".

    Thanks a lot for the help of anyones!

    ApplicationUI.cpp

    #include "applicationui.hpp".

    #include
    #include
    #include

    using namespace bb::cascades;

    ApplicationUI::ApplicationUI():
    QObject()
    {

    Create the scene of active main.qml, the parent document is defined
    to make sure that the document is destroyed properly stopped down.
    QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);

    Create the root for the UI object
    AbstractPane * root = qml->() createRootObject;
    root-> setProperty ("labelText", factorial (5)); ERROR HERE (factorial was not declared in this scope)

    Root object created together as the stage of the application
    Application::instance()-> setScene (root);
    }

    chain of factorial (long n)
    {
    long years = 1;
    for (long I = 2; I have<= n;="" ++i)="">
    years = years * i;
    If (SNA< 0)="">
    Returns - 1;
    }
    }
    Return QString::number (years);
    }

    Application.HPP

    #ifndef ApplicationUI_HPP_
    #define ApplicationUI_HPP_

    #include

    class MyCppObject;

    Class ApplicationUI: public QObject
    {
    Q_OBJECT
    public:
    ApplicationUI();

    Virtual ~ ApplicationUI() {}
    String factorial (long n) () / /ERROR HERE ('string' is not a type, without return, based on non-void return)

    };

    #endif / * ApplicationUI_HPP_ * /.

    hand. QML

    import bb.cascades 1.4

    {Page}
    property alias labelText: label.text
    {Of container
    {Label
    ID: label
    text: "Label".
    }

    Button {}
    objectName: 'button '.
    text: "Button".
    }
    }
    }

    the error message is "string does not name a type" because the string is not a type of data in c ++.
    (and in java, it would be a String with a capital S)

    Use QString.

  • help RGBPickerProvider QML

    Hi everyone ive been trying to create the custom selector UI under documentation ive done but get theses problems as the path location Type Resource Description
    Fatal error: RGBPickerProvider.h: main.cpp and aplicationui I'm in both the files ive got a symble of Red Cross saying several marker at the level of the line

    unresoved - registration: RGBpicker provider.h

    -the breakpoint line: CPP

    -fatal error: RGBPickerProvider.h:

    any help I would be greatfull for thanks a lot

    Of

    Mike

    Welcome to the forums.

    Given that you typed this out rather than copied and pasted, it is difficult to say what is the problem of this small excerpt.

    Basically everything what means error is that, for some reason, he was unable to understand or find the header of the class.

    You have a space in the name of the file and not in the third, I would like to avoid putting spaces in filenames to begin with.

    If the space was just put typing your it here so make sure that you have included the header in the class or main using it in.

    Make sure your headers are in the same place in your wprokspace as other sources files or if not to learn how to add additional paths to the .pro file.

    You gave very little to go, but I hope that something that precedes will spark an idea on what it could be.

  • HELP the QML Notification problems

    I don't know why my custom sounds and the icon does not work. I checked my sounds and icons are really in the right place and they are valid.

    //imported this import bb.platform 1.2 // I am running it to my device with 10.2 OS//I've also added the permissions and the proper library in the pro file
    
    Notification
            {
                id: theNotification
                soundUrl: "asset:///sounds/ios.wav"
                iconUrl: "asset:///images/icon.png"
                title: "Test"
                body: "Test"
            }
    
    then I call this in a button theNotification.notify();
    

    Also how can I continue to add notifications? When he has already added a notification in the hub, you may not add another new and nothing happens.

    Also is there a way to disable its default Notifications?

    I hope that a solution to this little problem.

    Hi, I tried your 2nd suggestion and did not work at all. no error and no notificaitons have been issued.

    I just used C++ and works perfectly. Thank you very much!

    I just built a function

    void ApplicationUI::notify(QString title, QString body)
    {
        Notification* notification = new Notification();
        notification->setTitle(title);
        notification->setBody(body);
        notification->notify();
    }
    

    So call whenever I need to display a Notification of Hub.

  • QML Compilation error: Incorrect Signal

    Hello

    After more than half of the year, I came back to development BB10, upgraded to the latest IDE and the latest version of the SDK, imported into a project and now I feel compilation with message error: incorrect signal. There is no change in the source codes so how project is compiled must change.

    Error looks like this:

    It is related to the onProPurchaseChanged signal in this code fragment

        attachedObjects: [
            ....
            Connections {
                target: _app
                onProPurchasedChanged: {
                    ....
                }
            }
        ]
    

    _APP of the object is inserted into the context help

    qml->setContextProperty("_app", this);
    

    Any idea that get rid you of the compile error? Syntax and sematics was OK in an earlier version of the IDE, app worked before.

    Thank you for any clue

    Tom

    OK, I'm going to answer my question by myself:

    The solution is quite simple. I simply add the declaration of signal in the connections object. Why it is necessary, if it wasn't in the past, I have still no idea. Hope this helps someone else too.

        attachedObjects: [
            ....
            Connections {
                target: _app            signal proPurchasedChanged            onProPurchasedChanged: {
                    ....
                }
            }
        ]
    
  • HELP the multiple ContactPicker in QML

    I have this code

    ActionItem
                {
                    title: "Invite Contacts"
                    ActionBar.placement: ActionBarPlacement.OnBar
                    imageSource: "asset:///images/titleAddFriend.png"
                    onTriggered:
                    {
                        contactPicker.open();
                    }
    
                    attachedObjects: ContactPicker
                    {
                        id: contactPicker
                        mode: ContactSelectionMode.Multiple
                        onContactsSelected:
                        {
                            for(var i = 0; i < selectedContactsIds.length; i++)
                            {
                                var phoneNumber = _app.getContactPhoneNumber(selectedContactsIds[i]);
                                console.log("PHONE: " + phoneNumber);
                            }
                        }
                    }
                }
    

    but does simply not multiple selector. It still operates as the single contact selector by default. I added a qml register type in main.cpp and libraries are also imported. any suggestions please? This problem is also present although 10.1 and OS 10.2.1 tried.

    I thought about it... its another case of QML it can not handle.  After testing your code, I noticed this error

    file:///apps/com.example.dynamicattach.testDev_namicattach58cf113_/native/assets//main.qml:51: ReferenceError: Can't find variable: ContactSelectionMode
    

    So I tried to import ContactSelectionMode qml as the selector is with no success.

    So, I stuck with c ++ for the switch and got the results of work

    The solution

    applicationUI.cpp

    #include 
    #include 
    
    void ApplicationUI::contacts()
    {
          ContactPicker *contactPicker = new ContactPicker();
          contactPicker->setMode(ContactSelectionMode::Multiple);
          contactPicker->setKindFilters(QSet()
               << bb::pim::contacts::AttributeKind::Phone);
    
          bool success = QObject::connect(contactPicker,
                 SIGNAL(contactsSelected(QList)),
                 this,
                 SLOT(onContactsSelected(QList)));
    
          if (success) { // Signal was successfully connected.
                contactPicker->open();
              } else { // Failed to connect to signal.
                qDebug() << "Didn't connect the picker signal";
              }
    }
    
    void ApplicationUI::onContactsSelected(const QList &contactIds) {
    
        qDebug() << "contacts" << contactIds;
    }
    

    applicationUI.hpp

    public:
        ApplicationUI(bb::cascades::Application *app);
        virtual ~ApplicationUI() { }
    
        Q_INVOKABLE void contacts();
    
    public slots:
        void onContactsSelected(const QList &contactIds);
    

    . QML

    Button {
                    id: contact
                    text: "Pick Contact"
                    onClicked: {
                        cpp.contacts();
                    }
    
                }
    

    Now, given that the function is entirely in c ++, you should be able to take your code to

    _app.getContactPhoneNumber(selectedContactsIds[i]);
    

    and just insert into onContactsSelected to get your phone numbers

    I hope that helps!  Now I know how to do it too =)

    P. S.

    If you are still having a problem where something must certainly work and it is not, it is very likely that you will succeed if you just pass it to the c code ++ like theres probably a problem with the QML support.

  • Help to understand the basics of the integration of Javascript/QML

    Hey all!

    I am just development of BB for the first time, so please bear with me. I'm not sure that understand the interaction between JS and QML. I understand that you can write JS in QML, particularly in managers of signals, and I used chunks of it with success. Also, I show/read by the "Javascript in QML" and JS linked in the pages of Qt, which helped a bit.

    However, I am having a few problems incorporating it into my code.  Could you take a look at this and point me in the right direction? (I'm also new to JS itself, so maybe that my mistakes are with this instead?)

    onTriggered: {}

    When an item is selected, we push the recipe Page in the attribute of file chosenItem.

    var chosenItem = dataModel.data (row);

     

    Create the content page and place on top of drill down for it.

    contentPage var = pillDetailPageDefinition.createObject ();

     

    Set the properties of content to reflect the selected image.

    contentpage.contentImageURL = chosenItem.thumbnail

    contentpage.contentName = chosenItem.name + ', ' + chosenItem.mass

     

    * Errors begin to surface in this block *.

    contentpage.contentConsumption = {}

    Guide bar = "With"

    Mistakes of the top line: 'missing}, unknown symbol "guideline", missing colon "guideline", etc.

     

    Boolean multiInstruction = false;

    Top line errors: inconsistent input boolean expected RBRACE

                            

    If {(chosenItem.withFood)

    guideline += "food";

    multiInstruction = true;

    }

    If {(chosenItem.withWater)

    If (multiInstruction) guideline += 'and ';

    guideline += 'water '.

    }

    Return to the guideline;

    }

     


    Thanks in advance! I feel I'm missing something incredibly small/basic

    try calling it without braces.

    You can also create a function directly in QML, no need to export to a js file unless you want to use other components (that are not subcomponents) as well.

    to learn more about the construction of Qt/QML parent, I suggest to read this doc API:
    http://Qt-project.org/doc/Qt-4.8/objecttrees.html

    createObject (this) would create a new component with the parent defined on the object class, and if this is destroyed a new is also destroyed. This is useful when you create components dynamically as you don't have to delete them manually later.

  • Help me, error when creating applications in the QML file

    I created a list of user interface and this error occurs, here's my whole code:

    import bb.cascades 1.0
    {Page}
    {To ListView
    ID: listview
    dataModel: {XmlDataModel}
    Source: "people.xml".
    }
    listItemComponents:]
    {ListItemComponent}
    type: "category".
    {CustomLisItem}
    dividerVisible: true
    {Label
    text: ListItemData.value
    Apply a text style to create a large font, "BOLD" with
    a specific color
    textStyle {}
    Base: SystemDefaults.TextStyles.BigText
    fontWeight: FontWeight.Bold
    color: Color.create("#7a184a")
    }
    } / / Label
    }
    },
    {ListItemComponent}
    type: 'person '.
    {StandardListItem}
    Title: ListItemData.name
    Description: ListItemData.born
    status: ListItemData.spouse
    imageSource: "asset: images / / / / ' + ListItemData.pic
    }
    }
    ] / / ListItemComponents
    } / / ListView
    }

    You misspelled CustomListItem.

  • Help with ListView in QML - loading of Json

    I'm losing my mind here. I had trouble getting even the file most basic json in a DataModel and filling of a list. I think what I really need, it is an example of a complex Json file processed, because that will provide an overview much more how these things work.

    Here is my code:

    import bb.cascades 1.3
    import bb.data 1.0
    
    Page {
        content: ListView {
            id: listView
            rootIndexPath: [2]
            dataModel: dataModel
    
            listItemComponents: [
                ListItemComponent {
                    id: item
                    type: "top"
                    StandardListItem {
                        title: ListItemData.game.name
                        description: ListItemData.viewers
                    }
                }
            ]
        }
        attachedObjects: [
            GroupDataModel {
                id: dataModel
            },
            DataSource {
                id: dataSource
                source: "sample.json"
                onDataLoaded: {
                    dataModel.insertList(data)
                    //console.log(data.top[0].name)
                }
                onError: {
                    console.log("There was an error with DataSource")
                }
            }
        ]
        onCreationCompleted: {
            dataSource.load();
        }
    }
    

    And here is sample.json:

    {
      "_links": {
        "self": "https://api.twitch.tv/kraken/games/top?limit=25&offset=0",
        "next": "https://api.twitch.tv/kraken/games/top?limit=25&offset=25"
      },
      "_total": 322,
      "top": [
        {
          "game": {
            "name": "League of Legends",
            "box": {
              "large": "http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends.jpg?w=272&h=380&fit=scale",
              "medium": "http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends.jpg?w=136&h=190&fit=scale",
              "small": "http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends.jpg?w=52&h=72&fit=scale",
              "template": "http://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends.jpg?w={width}&h={height}&fit=scale"
            },
            "logo": {
              "large": "http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends.jpg?w=240&h=144&fit=scale",
              "medium": "http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends.jpg?w=120&h=72&fit=scale",
              "small": "http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends.jpg?w=60&h=36&fit=scale",
              "template": "http://static-cdn.jtvnw.net/ttv-logoart/League%20of%20Legends.jpg?w={width}&h={height}&fit=scale"
            },
            "_links": {},
            "_id": 21779,
            "giantbomb_id": 24024
          },
          "viewers": 23873,
          "channels": 305
        }
      ]
    }
    

    My goal is to show a list of names of games, as well as viewers. How the hell can I do?

    If this is all of the JSON file, you have an error because it is not a list, but object.

    In addition, GroupDataModel have two type of header and item not your top items.

    Try this code:

    import bb.cascades 1.3
    import bb.data 1.0
    
    Page {
        content: ListView {
            id: listView
            dataModel: dataModel
    
            listItemComponents: [
                ListItemComponent {
                    id: item
                    type: "item"
                    StandardListItem {
                        title: ListItemData.top[0].game.name
                        description: ListItemData.top[0].viewers
                    }
                }
            ]
        }
        attachedObjects: [
            GroupDataModel {
                id: dataModel
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource
                source: "sample.json"
                onDataLoaded: {
                    dataModel.insert(data)
                    //console.log(data.top[0].name)
                }
                onError: {
                    console.log("There was an error with DataSource")
                }
            }
        ]
        onCreationCompleted: {
            dataSource.load();
        }
    }
    
  • Connection signal of C++ with slot QML

    Before ask you, I searched for answers to this question, but I have not found a satisfactory example.

    I have set up a service network in C++ that performs queries to REST against a backend. An example query would be to download a given element, the id of the item.

    Once the item is extracted, I emit a signal such as:

    itemReceived(QString& itemId, QString& item);
    

    My question is how can I wire this signal to the slot in a QML page so that the status of the answer? I tried to connect the signal on the Qml in C++ slot, as follows:

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    QObject::connect(this->networkingService,
                         SIGNAL(itemReceived(QString&, QString&)),
                         qml, SLOT(onItemReceived(QString&, QString&));
    

    With a correspondent QML "slot" like this:

        function onItemReceived(x, y) {
            console.log("*********************");
            console.log("Item Received!");
            console.log("*********************");
        }
    

    But it does not work. I also tried using the element of connection of the QtQuick lib, but this also fails.

    Any help would be greatly appreciated. Even if he were to propose a better architecture for the "path of the cascades. Thank you!

    In C++:
    QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);
    QML-> setContextProperty ("_app", this);

    In QML:
    {Page}
    onCreationCompleted: {}
    _APP.itemReceived.connect (onItemReceived)
    }

    function onItemReceived (x, y) {}
    Console.log("***");
    Console.log ("point received!");
    Console.log("***");
    }

    // ...
    }

  • HOWTO: Translation Live in C++ similar to re-translate in QML

    WARNING: To come long post!

    If you've built (or building) your apps BlackBerry 10 Aboriginal stunts with internationalization in mind, then you have probably dotted with QML qsTr() calls and macros tr() C++ code. When your application starts the text wrapped in qsTr() or tr() is replaced by the localized text for the local unit and the language (if defined, otherwise default text is used). This works fine unless you change the language setting on your device while your application is running. Unless you take measures to propagate the change to the language through your live webcam app, the text displayed in your application will not match the settting of language new device only when your application is restarted. QML provides this translation of 'direct' with the re-translation class, which can be used with qsTr() update of translations that soon the language setting of the device is changed:

    Page {   Container {      Label {         id: label01
    
             // ---This label's text will be live translated         text: qsTr("Label 1") + Retranslate.onLanguageChanged      }      Label {         id: label02
    
             // ---This label's text will be static translated         text: qsTr("Label 2")      }   }}
    

    In this example, label01 will be his attribute of translated text live as it is updated as soon as the device language is changed. However, label02 will have only his attribute of text translated when the software is first started and the language changes following while the application is running will not update to it.

    With the help of the re-translation with QML class makes direct translation as simple as the addition of a small amount of code just after each use of qsTr(), but C++ does provide no such convenience. To implement the translation directly in C++ code, it is necessary to call setXXX() for a string with the macro tr() attribute slot once to do the initial translation and then connect the setXXX() slot to an instance of LocaleHandler that emits a signal every time the language (or locale) changes. It's complicated by the fact that the LocaleHandler knows that the language has changed, but he doesn't know which key text to provide openings, it is attached to the then must fix the LocaleHandler signal to an intermediate location that knows what translation of key to use for this attribute, and then emits a different signal with the key as a parameter that must be connected to the slot machine control setXXX() . This means that, for every single control attribute you want live, translate you'll need a separate intermediate location set somewhere, a signal linked to this site and two calls QObject::connect(). For EACH attribute that we want to live translation. Of course, this becomes very ugly, very fast.

    I prefer to use C++ with QML little or not to expose my app pages so I was determined to find a solution that was easier to use than retranslating in QML (or almost) and after some trial and error I came up with a solution that I am very satisfied. The core of this technique is a C++ class called LiveTranslator. The syntax to use is a bit more complicated to use QML re-translation, but as re-translation you only need to add a line of code for each attribute that you want to translate live. Here is the header for LiveTranslator:

    #ifndef LIVETRANSLATOR_HPP_
    #define LIVETRANSLATOR_HPP_
    
    #include 
    
    using namespace bb::cascades;
    
    class LiveTranslator: public QObject {
        Q_OBJECT
    
        QString _key;
        QString _context;
    
        static LocaleHandler* _localeHandler;
    
    public:
        LiveTranslator( const QString& context, const QString& key, QObject* target, const char* slot );
        static void setLocaleHandler( LocaleHandler* localeHandler );
    
    private slots:
        void localeOrLanguageChangedHandler();
    
    signals:
        void translate( const QString& string );
    };
    
    #endif /* LIVETRANSLATOR_HPP_ */
    

    .. .and the body...

    #include "LiveTranslator.hpp"
    
    // ---Initialize the locale handler pointer on app startup so we can tell if it has been set properly later
    LocaleHandler* LiveTranslator::_localeHandler = 0;
    
    // ---Note that the target control is also used as the parent so the live translator dies when the control does
    LiveTranslator::LiveTranslator( const QString& context, const QString& key, QObject* target, const char* slot ) :
            QObject( target ) {
    
        bool success;
        Q_UNUSED( success );
    
        // ---Save the context and key string
        this->_key = key;
        this->_context = context;
    
        // ---Die (during debug) if the locale handler hasn't been set properly before use
        Q_ASSERT( LiveTranslator::_localeHandler );
    
        // ---Watch for locale or language changes
        success = QObject::connect( LiveTranslator::_localeHandler, SIGNAL( localeOrLanguageChanged() ), SLOT( localeOrLanguageChangedHandler() ) );
        Q_ASSERT( success );
    
        // ---Trigger specified slot when locale or language changes
        success = QObject::connect( this, SIGNAL( translate( const QString& ) ), target, slot );
        Q_ASSERT( success );
    }
    
    void LiveTranslator::localeOrLanguageChangedHandler() {
        // ---Use the specified slot on the target to update the appropriate string attribute with the translated key
        emit translate( QCoreApplication::translate( this->_context.toLocal8Bit().constData(), this->_key.toLocal8Bit().constData() ) );
    }
    
    // ---This function MUST be called once with a valid LocaleHandler before any LiveTranslator classes are instantiated
    void LiveTranslator::setLocaleHandler( LocaleHandler* localeHandler ) {
        LiveTranslator::_localeHandler = localeHandler;
    }
    

    LiveTranslator encapsulates all the ugly stuff, including remembering the key to the translation, the intermediate signal/slot, and all signal/slot connections necessary for direct translation. Use is as simple as creating an instance of LiveTranslator, passing the constructor the translation for the attribute key (and the context, but more on that later), the Visual control of the target and the location on the control that accepts the update of translation. Note that tr() only works with static keys chains...

    // ---This is valid
    QString str1 = tr("string one");
    
    // ---This is not!
    Qstring str1 = "string one";
    QString str2 = tr(str1);
    

    .. .so instead tr(), LiveTranslator must use QCoreApplication translate() internally.

    An example of use of LiveTranslator :

    MyClass::MyClass() {
        Label* label = Label::create().text( tr("Label one") );
        new LiveTranslator( "MyClass", "Label one", label, SLOT(setText(const QString&)));
    
        Option* option = Option::create().text( tr("Option one") ).description( tr("Option one description") );
        new LiveTranslator( "MyClass", "Option one", option, SLOT(setText(const QString&)));
        new LiveTranslator( "MyClass", "Option one description", option, SLOT(setDescription(const QString&)));
    
        ActionItem* actionItem = Option::create().title( tr("Action one") );
        new LiveTranslator( "MyClass", "Action one", actionItem, SLOT(setTitle(const QString&)));
    }
    

    Note that there is no need to save a reference to the new instance LiveTranslator since the constructor sets the 'target' as a parent control. When the control is destroyed by your app the LiveTranslator will go with him. The first parameter to the constructor LiveTranslator is the 'context' where the translation key. When you use the macro tr() (or function qsTr() QML) the code parser mentions of where he found the key and stores it in the translation file. This way you can use the same key for translation on different pages, and if the context is different, you could have them translated differently. The parser doesn't know anything about the LiveTranslator class but it must indicate the context explicitly. For C++, the context is always the name of the class containing the code that you are translating. In addition, in case it is not obvious, the "key" parameter must be the same value used with tr() on the input line.

    There is one thing that you must do before using LiveTranslator in your C++ code and that is to give it a LocaleHandler to work with. Rather than force you to spend a LocaleHandler for each instance of LiveTranslator, you tell LiveTranslator that one to use only once with a static function call. If you created your application from one of the Momentics models then you already have a Manager, you can use:

    ApplicationUI::ApplicationUI() : QObject() {
        // prepare the localization
        m_pTranslator = new QTranslator( this );
        m_pLocaleHandler = new LocaleHandler( this );
    
        // Use this locale handler for all the live translations too
        LiveTranslator::setLocaleHandler( m_pLocaleHandler );
    
        ...
        ...
        ...
    }
    

    I enclose the source for LiveTranslator so all you need to do to get the direct translation working in your BB10 native C++ code is extract the zip in your src directory, add a call to LiveTranslator::setLocaleHandler() in your main application class constructor, and then call new LiveTranslator (...) with the appropriate settings for each attribute of the control you want to be living translated. I hope that is useful to the native BlackBerry 10 development community wonderful (and long-suffering).

    IMPORTANT!

    The instructions posted above have been extended and improved to work with some additional user interface controls such as SystemDialog and SystemUiButton. It was published with a link to a sample application on GitHub as an guest article on the Blog of Dev of BlackBerry. Additional functionality has been added to the original code shown above, then the blog article and GitHub example now consider the definitive description of this technique.

    See you soon.

  • QML Cascades and to 'SCREEN_IDLE_MODE_KEEP_AWAKE' to work

    I have a QML driven application works very well, but after the usual delay, the display shuts off.  I need a way to keep it.

    I tried adding a "ForeignWindow" to my QML and then use FindChild to find the window, tie it to a ForeignWindow pointer and use it.  I have no errors, but the screen stays off.

    So, if someone got everything a QML Cascades driven UI app actually keep the screen on, please share your secret.

    Thank you

    Bryan

    Well, I'm this marking as closed in what I found a method to keep the screen awake (until it is actually completely supported in Cascades.

    The method was built with the participation of two people and a lot of research.  Here is the result

    (1) create a new thread

    (2) in the thread create a screen context

    (3) events ask for screen and navigator

    (4) when you get a message from idle screen, inject a key event in the queue of the screen

    Works very well.  Thank you all for your help

  • Foldable list help

    Hello

    Help QML and Javascript pro.  So far, things work fine, I can get the list to load and collapse but I can't edit the styles of the components.  When I debug it seems to ignore the component settings that I have.  I used the sample code from this Blackberry Dev Blog post to lead me to what I have now.

    I tried several different things and currently have the following executable code (just don't do what I want):

    hand. QML

    import bb.cascades 1.0
    
    Page {
        id: homeScreen
    
        //Background container
        Container {
            objectName: "mind_template_preferences"
            topPadding: 200
    
            //Background
            background: backgroundPaint.imagePaint
            attachedObjects: [
                ImagePaintDefinition {
                    id: backgroundPaint
                    imageSource: "img/editingBG.png"
                    repeatPattern: RepeatPattern.XY
                }
            ]//End Background
    
            //Elements
            Container {
                ExpandableItem {
                    prefHeader: "Data To Track"
                    prefList: "models/trackData.xml"
                    expandImage: "img/plus.png";
                    collapseImage: "img/minus.png";
                    prefVisible: false
                }
                ExpandableItem {
                    prefHeader: "Auto Reports"
                    prefList: "models/trackData.xml"
                    expandImage: "img/plus.png";
                    collapseImage: "img/minus.png";
                    prefVisible: true
                }
            }//End Elements
        }//End Background Container
    }//End Page
    

    ExpandableItem.qml

    import bb.cascades 1.0
    
    Container {
        property alias prefHeader: btnHeader.text
        property alias prefList: modelSource.source
        property alias prefVisible: xmlBody.visible
        property string collapseImage
        property string expandImage
        onPrefVisibleChanged: {
            if (prefVisible) {
                btnHeader.imageSource = collapseImage;
            } else {
                btnHeader.imageSource = expandImage;
            }
        }
    
        Button {
            id: btnHeader
            text: "default header"
            preferredWidth: maxWidth
            imageSource: collapseImage
            onClicked: {
                if (prefVisible) {
                    xmlBody.visible = false;
                    btnHeader.imageSource = expandImage;
                } else {
                    xmlBody.visible = true;
                    btnHeader.imageSource = collapseImage;
                }
            }
        }
    
        ListView {
            id: xmlBody
            dataModel: XmlDataModel {
                id: modelSource
                           source: "model default"}
           //List of Components
           listItemComponents: [  
    
               //Component One
               ListItemComponent {
                   type: listItem
                   Container {
                   Label { text: ListItemData.title
                           textStyle.color: Color.create("#ff0173ff")}
                   CheckBox {
                    checked: false}
                   }
               }//End Component One
    
           ]//End List of Components
        }//End List View
    }
    

    dataTrack.xml

    
        
        
        
            
            
    
    

    Okay I got it.  Simple Bobo.  I forgot the name of element xml in quotes.

    This was the fix:

               //Component One
               ListItemComponent {
                   type: "listItem"
                   Container {}}
    
  • Using C++ in QML classes: need for Clarification

    I have read the document using classes in QML C++ and understood that we must call qmlRegisterType before using C++ in QML classes.

    But I found that some (or all?) of the classes can be used in QML without call qmlRegisterType in advance.

    Example of

    import bb.device 1.0
    
    Page {
      attachedObjects: [VibrationController {id: qmlvib}]
      Container{
           Button {
                        text: "Test vibrate"
                        horizontalAlignment: HorizontalAlignment.Center
                        onClicked: qmlvib.start(100,100)
                       }
        }
    }
    

    I also found the SensorDemo project using many classes of QML sensor final qmlRegisterType<>(). But it does not call qmlRegisterType<>for VibrationController (?).

    I wish I had a few questions:

    1. How will I know which classes can be used in QML without qmlRegisterType<>()? Is there a list or the rule to help me know?

    2. what should I look at to decide using C++ class in QML directly (without qmlRegisterType<>(()) or with qmlRegisterType<>(): as the performance, memory management,...?

    3. If you can choose to use the C++ in QML class directly (without qmlRegisterType<>(()), BB shoud put it in the paper?

    Sorry for the many questions. I'm just a beginner on BB.

    Thank you very much!

    (1) I think that some classes are pre-registered. If it works without adding it yourself: looks like it was a.
    (2) I don't think that there is a performance issue with the help of registerType
    (3) No, there is not, just of the classes that are recorded automatically by the system.

  • Using C++ in QML classes in app without head: refers to 'bb::device:VibrationController:staticMetaObject' the undefined

    Hi, I've been weeks of work on the BB and had a lot of problems. Some of them have been resolved, some were not without the support of the forum.

    Now I have a great difficulty that I can't find answer by Googling.

    I am grateful to some body can help.

    Here's a simple case that make the big problem for me:

    1. create an app without head with Momentics. 2 project will be generated HeadlessApp and HeadlessAppService.

    Without modification, this code works well.

    2. I'm link below to use VibrationController in HeadlessAppService: https://developer.blackberry.com/native/documentation/dev/integrating_cpp_qml/index.html#usingcclass...

    below the code has been added:

    -Add codes below to main.cpp HeadlessAppService

    #include 
    using namespace bb::device;
    

    then add qmlRegisterType as below

    Q_DECL_EXPORT int main(int argc, char **argv)
    {
    
       Application app(argc, argv);
    
       qmlRegisterType("bb.vibrationController", 1, 0, "VibrationController");
       ApplicationUI appui;
       return Application::exec();
    }
    

    3. to confirm the new code, I just right click on the project and select build project.

    Bang! I got several error I don't understand. (red lines are errors)

    08:44:30 **** Incremental Build of configuration Device-Debug for project headlessTest ****
    make -j4 Device-Debug
    make -C .//translations -f Makefile update
    make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
    C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/lupdate headlessTest.pro
    Updating 'headlessTest.ts'...
        Found 2 source text(s) (0 new and 2 already existing)
    make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
    make -C .//translations -f Makefile release
    make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
    C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/lrelease headlessTest.pro
    Updating 'D:/BB-dev/momentics-workspace/headlessTest/translations/headlessTest.qm'...
        Generated 0 translation(s) (0 finished and 0 unfinished)
        Ignored 2 untranslated source text(s)
    make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
    make -C ./arm -f Makefile debug
    make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
    make -f Makefile.Debug
    make[2]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
    qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -o o.le-v7-g/headlessTest o.le-v7-g/.obj/applicationui.o o.le-v7-g/.obj/main.o o.le-v7-g/.obj/moc_applicationui.o    -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/bb1 -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/lib -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -LC:/bbndk/target_10_3_1_995/qnx6//usr/lib/qt4/lib -lbb -lbbsystem -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps
    o.le-v7-g/.obj/main.o: In function `int qmlRegisterType(char const*, int, int, char const*)':
    c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:191: undefined reference to `bb::device::VibrationController::staticMetaObject'
    o.le-v7-g/.obj/main.o: In function `QDeclarativeElement':
    c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:87: undefined reference to `bb::device::VibrationController::VibrationController(QObject*)'
    o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x8): undefined reference to `bb::device::VibrationController::metaObject() const'
    o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0xc): undefined reference to `bb::device::VibrationController::qt_metacast(char const*)'
    o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x10): undefined reference to `bb::device::VibrationController::qt_metacall(QMetaObject::Call, int, void**)'
    o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x8): undefined reference to `typeinfo for bb::device::VibrationController'
    o.le-v7-g/.obj/main.o: In function `~QDeclarativeElement':
    c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `bb::device::VibrationController::~VibrationController()'
    c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `bb::device::VibrationController::~VibrationController()'cc: C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/ntoarm-ld caught signal 1
    Makefile.Debug:103: recipe for target 'o.le-v7-g/headlessTest' failed
    make[2]: *** [o.le-v7-g/headlessTest] Error 1make[2]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
    make[1]: *** [debug] Error 2
    Makefile:50: recipe for target 'debug' failed
    make: *** [Device-Debug] Error 2make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
    mk/cs-base.mk:31: recipe for target 'Device-Debug' failed
    08:44:31 Build Finished (took 1s.47ms)
    

    I give up!

    Why adding simple code can be a problem? Please help me!

    Thank you very much!

    You must add this code into main.cpp to your HeadlessApp, not HeadlessAppService. Your spare part cannot run any UI stuff, trying to save an object any for QML is part of the things in the user interface.

    But anyway, reading your newspaper from the console, you seem to put in the right place anyway. Did you add this to your headlessTest.pro file:
    LIBS +=-lbbdevice

Maybe you are looking for

  • How can I get Firefox looking for my computer for the plugins that are already there?

    How can I get Firefox looking for my computer for the plugins that are already there? Adobe Flash player is already on my computer from IE 8. How can I get Firefox to see that it is already on my PC and use it so I don't have to download it again and

  • Windows XP on Compaq CQ61-410US

    Hello, I recently bought a Compaq CQ61-410US and he was giving me no trouble. I need to install Widnows XP out there because I need to run programs that won't run in Windows 7 Home premium x 64. So I tried to slipstream drivers and all, but I get the

  • scan mutiple pages into a single pdf

    Printer Envy 120. How to scan multiple pages into a single document?  If the solution is to change the resolution to 300 dpi or less, how do I do that?  Thank you!

  • Photosmart D110a: installed the new HP black ink cartridge and now the black ink does not print

    Just installed a new print 60xl cartridge to replace the one that was being ink. Now the black ink basically does not print. I cleaned the cartridges 4 times and run all Diagnostics pages. The black prints just a small piece of the upper part of the

  • Reset codes for SIM & PUK?

    original title: RESET to the SIM card AND the PUK CODES? I bought a windows phone that forces me to put in my PIN, now he says between puk sim error that I'm looking for codes for sim card reset