Injection of C++ in qml

Is it possible to create a QML document, for example a page with 2 containers and id, then build the content for containers in C++ and insert the content into the container with the relevant id?

I have reviewed the documentation of QML and C++ integration, but here they only show you how to manipulate the values in qml via C++ and not to generate and inject the content via C++.

Hope that I made it quite clear. Any thoughts?

The sample "kakel" should show you want you need.

Tags: BlackBerry Developers

Similar Questions

  • The sample does not not on the BlackBerry website

    Hi, again I am trying to run an example of BlackBerry web site. This time, this one:

    "C++ objects in QML injection" (the last section at the bottom) - page:

    https://developer.BlackBerry.com/Cascades/documentation/dev/integrating_cpp_qml/index.html,

    This is my code:

    CPP file

    #include "CombineCppAndQml.hpp"
    
    #include 
    #include 
    #include 
    
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    using namespace bb::cascades;
    
    CombineCppAndQml::CombineCppAndQml(bb::cascades::Application *app)
    : QObject(app)
    {
        QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
        qml->setContextProperty("injection", this);
        AbstractPane *root = qml->createRootObject();
        app->setScene(root);
    }
    
    void CombineCppAndQml::injectContainer()
    {
        // Creates the container and adds it to the root
        // container in qml
        mRootContainer->add(Container::create()
            .background(Color::Red)
            .preferredSize(200,200)
            .bottomMargin(20)
            .horizontal(HorizontalAlignment::Center));
    }
    

    PPS file

    #ifndef CombineCppAndQml_HPP_
    #define CombineCppAndQml_HPP_
    
    #include 
    
     #include 
    #include 
    
    namespace bb { namespace cascades { class Application; }}
    
    using namespace bb::cascades;
    
    class CombineCppAndQml : public QObject
    {
        Q_OBJECT
    public:
        CombineCppAndQml(bb::cascades::Application *app);
        virtual ~CombineCppAndQml() {}
    
        // By using Q_INVOKABLE we can call it from qml
        Q_INVOKABLE void injectContainer();
    
    private:
        Page *appPage;
        Container *mRootContainer;
    };
    
    #endif /* Test_Hpp_ */
    

    and the qml file on the Web Site.

    import bb.cascades 1.0
    
    Page {
        // Allows the user to scroll vertically
        ScrollView {
            scrollViewProperties {
                scrollMode: ScrollMode.Vertical
            }
            // Root container that containers from C++ are added to
            Container {
                objectName: "rootContainer"
                layout: StackLayout {}
                // Button that calls the C++ function to add a
                // new container. The selectedIndex from the drop down
                // is passed to C++.
                Button {
                    text: "Add container"
                    onClicked: {
                        injection.injectContainer();
                    }
                }
            }
        }
    }
    

    When I run it, I actually see the button, but when I click it to open the second container, my application gets reduced to the place to show the new container.

    PPS. I also have a class separate main.cpp which calls the class CombineCppAndQml.

    Any help much appreciated.

    Please add the following line to your CombineCppAndQml constructor

    mRootContainer = root-> findChild(("" rootContainer"'));

     

    CombineCppAndQml::CombineCppAndQml(bb::cascades::Application *app)
    : QObject(app)
    {
        QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
        qml->setContextProperty("injection", this);
        AbstractPane *root = qml->createRootObject();
        app->setScene(root);
    
        mRootContainer = root->findChild("rootContainer");
    }
    

    -Dishooom

    --------------------------------------------------------------------------------------------------------------------------------

    Hope this helps

     

  • Adding images dynamically - tutorial for examples does not work

    I am using the SDK Gold and work through the tutorials. I want to add dynamically images of C++. The tutorial that I use is here:

    https://developer.BlackBerry.com/cascades/documentation/dev/integrating_cpp_qml/ (under the heading "Injecting C++ objects in QML").

    I have copy and paste the main.cpp, TestApp.hpp and TestApp.cpp into a new project. He compiled and ran on my device, but when I click on the button 'Add the container' seg application vulnerabilities and ends.

    I understand that this is caused by a NULL pointer, so I added:

    This-> mRootContainer = new bb::cascades::Container();

    for the Builder. Now it does not segfault when I press the button 'Add the container', but again, it does not actually add the container (it adds nothing visible).

    How can I use the concepts described in this tutorial to add an image at run time?

    I managed to understand. The example provided in the tutorial defnitely badly, which is very annoying and frustrating for those of us learning to code for BB10. Not only that, but the "barrier to entry" is hard enough, and if Blackberry to their ecosystem to flourish, documentation and tutorials must be accurate and easy to follow.

    The constructor should be something like:

    TestApp::TestApp(bb::cascades::Application *app) : QObject(app)
    {
      QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
      qml->setContextProperty("injection", this);
      Page *appPage = qml->createRootObject();
      mRootContainer = appPage->findChild("rootContainer");
      app->setScene(appPage);
    }
    
  • Injection containers QML on the fly?

    Hello, I'm quite new to the Blackberry development, so far, I can say that I love it. I'm working on an application that requires me to be able to change the QML that is inside a container on the fly. For example:

            // MAIN CONTAINER PLACEHOLDER
            Container {
                id: mainContainer
                // Any way to inject fully built qml files right here, and swap them out on the fly?
            }
    

    I have a menu on the left in the form of a ListView when you press a button at the top left, the current view moves to the right and allows you to use the navigation. When you select a new navigation item, I want to replace what is in the "key container" with the QML file that is appropriate for what the user has selected.

    Thanks in advance for any help!

    You're better off using a delegate control for your particular problem.

    Take a look at the example of Cookbook qml stunts to see how it is easy to do.

    http://developer.BlackBerry.com/Cascades/sampleapps/

  • 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

  • Possible to extract a part of code HTML of WebView and exposes to QML?

    Spending a few hours to research this, but not really sure.

    My application has a lyrics Viewer, it opens the page with a WebView then uses evaluateJavaScript to strip all normal visible header and the actual words, everything works great and leaves me with just the text words.

    I would like to take that text and somehow move it to QML so I can strip things html and ending up with a gross QString with the text of the words and finally display it with a tag, but not really sure how.

         webView.evaluateJavaScript(
                             "var content = document.getElementById('mw-content-text');" +
                             "while (document.head.firstChild) { document.head.removeChild(document.head.firstChild); }" +
                             "while (document.body.firstChild) { document.body.removeChild(document.body.firstChild); }" +
                             "var header = document.createElement('h1');" +
                             "header.style.color = ('white');"+
                             "header.innerHTML = '" +  lyricsDataArtist+ " " +  lyricsDataSong + " Lyrics';" +
                             "document.body.appendChild(header);" +
                             "var lyrics = content.getElementsByClassName('lyricbox')[0];" +
                             "lyrics.removeChild(lyrics.firstChild);" +
                             "document.body.appendChild(lyrics);"+
                             "lyrics.style.color = ('white');"+
                             "document.body.style.background = ('black');"
                             );
    

    Any ideas appriciated.

    Thank you

    I suspect you can do what you need by calling navigator.cascades.postMessage () of your injected JavaScript and catch with the WebView::messageReceived signal. I use this mechanism in my application support to get stuff to the pages loaded in my C++ code, but it also works well with QML.

    Signal WebView::messageReceived() documentation

  • How to use cppObject in several QML files?

    I have a variable cppObject of context set as usual:

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

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

    And it works very well in the main.qml.

    Problem is that it doesn't work in the second pagetwo.qml of QML files that is created on the fly in main.qml when the button is clicked.

    No idea how access C++ pagetwo.qml?

    Thank you.

    I did an application of simple test to replicate this, but I see "HELLO FROM C++" on two pages:

    hand. QML

    // Navigation pane project template
    import bb.cascades 1.0
    
    NavigationPane {
        id: navigationPane
        Page {
            Container {
                Label {
                    text: injection.testFunc()
                }
                Button {
                    text: "Other page"
                    onClicked: {
                        // show detail page when the button is clicked
                        var page = getSecondPage();
                        navigationPane.push(page);
                    }
                    property Page secondPage
                    function getSecondPage() {
                        if (! secondPage) {
                            secondPage = secondPageDefinition.createObject();
                        }
                        return secondPage;
                    }
                    attachedObjects: [
                        ComponentDefinition {
                            id: secondPageDefinition
                            source: "DetailsPage.qml"
                        }
                    ]
                }
            }
        }
    }
    

    DetailsPage.qml:

    // Navigation pane project template
    import bb.cascades 1.0
    
    Page {
        Container {
            Label {
                text: injection.testFunc()
            }
        }
    }
    

    TestEmpty3.cpp:

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

    ...

    QString TestEmpty3::testFunc()
    {
        return "HELLO FROM C++";
    }
    

    TestEmpty3.h:

        Q_INVOKABLE QString testFunc();
    
  • Keeping a DataModel object through several pages of QML

    Hello

    I have a simple question, but so far I have not been able to grasp the exact application. So I have a DataModel.cpp object that loads data from a JSON data file.

    On my page main qml, the data model object is charged by attaching it with the following code...

          // The model itself is a QListDataModel defined in       // mydatamodel.h and registered as a type in the       // creation of the application.
          MyDataModel
          {
            id: dataModel
    
            // The path to the JSON file with initial data, this file         // will be moved to the data folder on the first launch         // of the application (in order to be able to get write access).
            jsonAssetPath: "app/native/assets/data/mydata.json"
          }
    

    Now, from the Main.qml page, I can launch methods, get / set properties, attached signals etc...  for the dataModel object. This is perfect, but in case my application consists of several pages... ie:

    Main.QML > AddNewItem.qml
               
    On the Add QML page, I add a new object to the object MyDataModel.

    > ViewItems.qml

    On the points of view, a ListView is bound to the MyDataModel object.

    > EditItem.qml

    The edit page is called, and the user to apply changes to the MyDataModel

    > ViewGraph.qml

    On the graphic page, the data is distributed to the MyDataModel to display a graph.

    I can re-gasket the MyDataModel on every pages, but this requires a complete reading of the JSON data set, but this isn't the right approach and leads in data refresh issue when adding, editing and deleting items.

    QML, how can an object RPC be passed from one page to another qml... I quickly tried to set a property on the ViewItems.qml variant, but it generates a qml error: the value of the property Type mismatch "dataModel". Expecting DataModel and found zero.

    Page
    {
      property variant data
    
      ...
    }
    

    A simpler solution might be creating the dataModel once in the C++ code and the injection of the instance (not type) as a context for QML property. It will be accessible from all pages.

    The above code, try to declare the property as regarding:

    property alias data : listViewId.dataModel
    

    then you can assign the qml outside:
    qmlpage. Data = dataModelId

  • How to pass 'SIGNAL' object as a parameter of QML

    Hi all

    I'm in a fundamental need for the object that caused the SIGNAL to occur,

    E.g. by a signal "onClicked" (in QML) of the button if I call a method of CRACK or Q_INVOKABLE, then what I have

    the purpose of the call?

    As,

    Button {}

    text: 'Add container ".

    onClicked: {}

    injection.playSound ();

    }

    }

    The code is taken from the tutorial. As you can see the "injection" is through "setContextProperty" and having

    "playSound" method I want to do something like this

    injection.playSound (' Button object which invoked this incrimination (onClicked) ');

    and the method in the class curresponding will look like.

    Q_INVOKABLE Sub playSound (bb::cascades:Button * buttonObject);

    One? Please help me in this regard.

    RIM, please take a look at these simple things and update documents.

    Kind regards

    Diagne

    In c ++ make your method in the header

    Q_INVOKABLE void playSound(QObject* buttonObject);
    

    In your cpp file

    MyClass::void playSound(QObject* buttonObject) {
    
    // Cast QObject to Button
    Button* myButton = qobject_cast

    In your QML file:

    injection.playSound(idOfYourButton);
    
  • Push CPC QML file?

    Hello guys,.

    Can we push a CPC of QML file? Something like

    ActionItem {
                    title: "Show Next Page"
                    onTriggered: {
                        var page = pageDefinition.createObject();
                        navgationPane.push(page);
                    }
                    attachedObjects: ComponentDefinition {
                        id: pageDefinition
                        source:"sample.qml"
                    }
    
                }
    

    Above code pushes QML file on the user interface. Like, I want to push a PPC on the user interface file.

    Possible solutions please?

    Thank you

    SHA.

    There is no way to give parameters to builders in QML, AFAIK. One option is to assign the default values, such as:
    Constructor (Application * app = NULL,...) so that the item can be built in QML and export these settings as properties too. So I think that the properties can be defined this way:

    content: MyComponentExportedFromCPP {
      property: value
    }
    

    You need to export objects that are used during initialization of QML so. It may be easier to inject the component from C++ code. In this way, you can call a single function in C++ code and create & initialize the object here.

    BTW, the way the Application object between instances of the object is not really necessary. It is a singleton and is accessible from anywhere:

    Application * app = Application::instance();

  • Application crashes when I expose C++ groupDataModel in qml

    Hello world

    in my application, I have discovered in a container list. When I click on one of these items in the list another page is loaded. The user interface is qml. It works very well. But now I want to add data to the page. If I do it crashes without warning or error.

    Here is the part of the code inportant:

    // Main.qml[...]onTriggered: {
                        var selectedItem = dataModel.data(indexPath);
    
                        var page = Qt.app.doLoadPageDetails();
    
                        navigationPane.push(page);
                    }[...]
    

    and here's what the doLoadPageDetails function defined in C++:

    // applicationui.cppPage* ApplicationUI::doLoadPageDetails(){    QmlDocument *qml = QmlDocument::create("asset:///PageDetails/PageDetails.qml").parent(this);
        qml->setContextProperty("app", this);
    
        Page* newPage = qml->createRootObject();
    
        // Create root object for the UI
         AbstractPane *root = qml->createRootObject();
    
         GroupDataModel *contactModel = new GroupDataModel;
            // ----> here I fill the data model with contacts
    
        // Connect to list view and update model
         ListView *contactListView = root->findChild("listContacts");
    
        contactListView->setDataModel(contactModel); <----- here my app crashes
    
        return newPage;
    }
    
    Page{
    ...
      Container{
    ...
        Container{
    ...
          ListView{
    ...
            id: listContacts
            dataModel: groupDataModel
            listItemComponents: [
              ListItemComponent {
                StandardListItem {
                  title: ListItemData.personName
                  description: ListItemData.mail
                  status: ListItemData.more
    ...
                }
              }
            ]
          }
        }
      }
    }
    

    I discovered by messages from debugging the accident happens when I want to inject the data to my page in qml model.

    Another point of my application, it works. But I can't know where the differences are. The only difference that I see so far is that in the other page ListView is inside a container. Not like here the ListView is inside a container which is once again within a container.

    Has anyone an idea what I can try to understand what is the cause of this accident? Without any error message, it is difficult to find the answer.

    Found the solution.

    I forgot to set the objectname in the ListView.

    ...ListView{  id: listContacts
      objectName: "listContacts"}
    

    I thought id would be the link between qml and C++.

  • Scan for SQL Injection

    Hello

    My site has been pulled down by the host. They sent me the following message is displayed:

    "We got information that there is injection of SQL code on our server and when we draw the injection point is for your domain. '.
    This is the type of attack:
    SQL generic sql update injection attempt - GET, SQL union select parameter - possible sql injection attempt - GET parameter

    That's why we need to disable your Web site for temporary.
    Please, scan your PC and the Web site of local files and make sure that your local files from PC and the site Web is virus-free.
    If you have you analyze local files on PC and the website also make sure that there is no virus please update this post once again.
    So we can reactivate your website. »

    Anyone know what I use for scanning for this please?

    Thank you

    Apple hosts your Web site?

  • Injection of JavaScript spamming after update

    Auto Firefox updated yesterday for me and immediately thereafter, I have been doing javascript injection spam which slows my computer down significantly. In addition, I can no longer use firebug or inspect element due to the spamming.

    I ran every virus scan that I start and nothing was found, so the update of firefox is the only thing I can think of as the cause.

    This is spam that comes to the past, how can I fix?

    "< script id ="dnt-inject-js"src ="https://sc1.checkpoint.com/dev/abine/scripts/inject.js"type =" application/x-javascript">"

    Which seems related to the Abine 'DoNotTrackMe' product, potentially provided through its partnership with ZoneAlarm (Check Point). Could check you that you have the latest version? To update the extensions, you can try this:

    Open the page modules using either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Then find the "gear" above the list button and ' Check for Updates '.

    If it continues to behave strangely, you may have to disable the extension and seek assistance from the Publisher (one which you have a relationship with).

  • liprary injected iOS

    I trast for all the app from the appstore

    but my last app (syssecinfo)

    After cheack my sound say, my phone has some liprary injected (as picture)

    If someone can help me remove this file and then I know that app make this file

    If your phone is not jailbroken then you have nothing to fear. This app is to create this kind of problem for many, and in reality, there is nothing of what needs to be done. Ignore the results.

  • Injection of error in error of type entry / exit system

    Hi I'm just starting in Labview and to this day, I've been joining void screws with Out error connecting to error in the next sub VI so I can capture errors at the end of the line of screws that are up of my program.

    It occurs to me that sometimes there are errors that occur that are not lifted by the system, but rather the dice indicate, for example, during a test product, when a test parameter is not a valid range. I wonder how to convert say a Boolean value for test pass / fail, an error with a message, that I can put in my path of the error. -What is in general?

    Some setting in context, I want to be able to test the two devices manufactured in a single sequence. If we fail a test sup, say a voltage is out of range, I want to inject than as a mistake and blow it at the end of this trial where he would be treated, and perhaps a group of experts on the GUI shows then in case of FAILURE or something similar. But enforcement should then immediately move on to the second device and start this test, without waiting for an acknowledgement so that when the tester returns, both have been tested and can determine what to do with them, according to the State of SUCCESS or FAILURE.

    I guess I asked how to remove a custom error and caught him? I've read a few articles about the error handling which doesn't really answer my question. Thanks for the tips!

    You can use the package by name to create the cluster error yourself with a Boolean value of True for the error (false is a warning), a number (0 for no error, a positive number of alert, negative number for an error) and a string for a message.

    If you must use the cluster of error in this way is a different matter.  I would recommend against it.  I consider the cluster of the error to be there for clerical errors and program errors.  Basically if your program runs correctly and that you have no hardware problems, and then a mistake should never appear on the cluster of error.  For the case where you are dealing with outages of a unit under test, pass/fail results, I consider that it is a normal part of the program, and that the data should be treated separately as part of your test data and not forced in the cluster of error data.  Check the condition of the success/failure of data to determine whether to execute all Subvi who should or should not run because a previous test failed.

Maybe you are looking for