objects vs C++ QML Dynamics

normally I use ComponentDefinitions and create / destroy all my UI of QML, who works fast and easy.

C++ only I use for business logic

Sometimes I have to create a C++ user interface controls, in this case a sheet, because:

If you use a spreadsheet with a NavigationPane or TabbedPane a TabbedPane root tab,

then c++ findChild can not find 'behind' the leaf objects

See this thread.

so my solution is to create / destroy these leaves of C++, because then I can ask these leaves to find objects.

It works perfectly and I will write blog and provide video HowTo handle this

Now my questions to all the C++ / Qt gurus out there:

What is the best way to create / destroy the leaf?

Here is my code:

1. open the sheet

called from QML

Create the spreadsheet and open it

void ApplicationUI::openAdminSheet() {
    QmlDocument *qmlAdminSheet = QmlDocument::create(
            "asset:///admin/AdminSheet.qml");
    qmlAdminSheet->setContextProperty("REST", mKinveyREST);
    qmlAdminSheet->setContextProperty("sercar10", this);
    mAdminSheet = qmlAdminSheet->createRootObject();
    mAdminSheet->setParent(this);
    mAdminSheet->open();
}

everything works perfectly

Sheet with TabbedPane opens on top

I put setContextProperty of classes where I invoke methods.

my business logic found objects such as DataModels, etc. drop-down menus using findChild() sheet as root

When the work is done and user wants to go back:

2. close the sheet

called from QML

close the worksheet

destroy the roadmap

call a function in QML. This function lives in the part of the root, so not executable from inside the leaf, but the roots after the closure of the leaf

void ApplicationUI::closeAdminSheet() {
    mAdminSheet->close();
    mAdminSheet->deleteLater();
    QMetaObject::invokeMethod(Application::instance()->scene(),
                "goHomeFromAdmin");
}

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

now my question:

I use deleteLater() to destroy the roadmap.

is it ok?

This means content will be deleted without danger?

is this the right place?

or should I only do the close() and connect to onClosed() Signal and then deleteLater?

What happens if the user closes and opens very fast sheet and openAdminSheet() creates a new worksheet before execution of deleteLater()?

Could it happen?

THX for tips HowTo, go the safer way to create / remove sheets of C++ - even if the user clicks repeatedly on open / close?

Hello

1. open the sheet

QmlDocument belongs to the default application. Where it is used to instantiate a single page, this page can be defined as the mother of QmlDocument, so they are destroyed together (this technique is described on this page).

...mAdminSheet = qmlAdminSheet->createRootObject();qmlAdminSheet->setParent(mAdminSheet);...

Loading of the QML will take probably some time, perhaps that is useful to load the document once and store it somewhere, spawning objects if necessary root while reusing the QML. While it should work in theory, I have not tried this.

2 destruction of the leaf

Close() is not instantaneous. deleteLater() is asynchronous, but most likely will trigger before close animation is over, so I think it's safer to wait until closed() is triggered and destroy the paper after that. This can be done on the spot, something like:

QObject::connect(mAdminSheet, SIGNAL(closed()), mAdminSheet, SLOT(deleteLater()));

children of mAdminSheet should be removed safely if their parents are properly defined.

> what happens if the user closes and opens the sheet very fast and openAdminSheet() create a new worksheet before deleteLater() run? Could it happen?

mAdminSheet is only a pointer (a memory address). The real object is not destroyed even if the pointer is overwritten.

After

mAdminSheet->deleteLater();

is called, it is prudent to reassing pointer in openAdminSheet. The old object will continue to exist until it is removed from the queue of events in Qt.

Tags: BlackBerry Developers

Similar Questions

  • ListView cannot see C++ object passed to QML via QmlDocument-> setContextProperty()

    I can access a C++ object using the QmlDocument function-> setContextProperty() in JavaScript inside most of the QML elements (such as containers, ImageButton, control etc.) happened, but can't access it from the JavaScript inside ListView. I get "ReferenceError: can't find variable: app. Why is this?

    Why is it a "problem"? It's probably just the way things work and should work. ListItemComponents are not really part of the scene graph/context since they exist only to be used during execution. Wait so the scope of the listItemcomponent unlike the rest of the document.

    The way around it, as described in the thread linked above is to create a function inside your listview that refers to the context property that you want to use. Then, your listitemcomponent has access to this feature of the listview.

  • Application CameraSettings for object Camera in QML?

    Hi, anyone knows how to apply CameraSettings to internal camera QML?

    Thank you.

    Hello

    Photobomber sample did this:

    https://github.com/BlackBerry/Cascades-samples/BLOB/master/photobomber/assets/main.QML

  • Cannot access object C++ in QML

    I have a NavigationPane defined in QML. In my C++ class, I create the NavigationPane and use setContextProperty in order to access the C++ class. However, when I try to use the QML context in the onCreationCompleted signal, the console displays a "ReferenceError: can't find variable: splashSample" error.

    The code is as follows:

    QML:

    import bb.cascades 1.0
    
    NavigationPane
    {
        id: navigationPane
        Page
        {
            onCreationCompleted:
            {
                splashSample.splashScreenDone.connect(navigationPane.push(getSecondPage()))
            }
            Container
            {
                background: Color.Black
                layout: DockLayout
                {
                }
                ImageView
                {
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                    imageSource: "asset:///images/splash.png"
                    onTouch:
                    {
                        // show detail page when the button is clicked
                        var page = getSecondPage();
                        console.debug("pushing detail " + page)
                        navigationPane.push(page);
                    }
                    property Page secondPage
                    function getSecondPage()
                    {
                        if (! secondPage)
                        {
                            secondPage = secondPageDefinition.createObject();
                        }
                        return secondPage;
                    }
                    attachedObjects:
                    [
                        ComponentDefinition
                        {
                            id: secondPageDefinition
                            source: "main.qml"
                        }
                    ]
                }
            }
        }
    }
    

    CPP file:

    SplashScreenSample::SplashScreenSample(bb::cascades::Application *app)
    : QObject(app)
    {
        QmlDocument *qml = QmlDocument::create("asset:///splash.qml").parent(this);
    
        AbstractPane *root = qml->createRootObject();
        qml->setContextProperty("splashSample", this);
    
        app->setScene(root);
    
    //  QTimer::singleShot(1000, this, SLOT(loadMainScreen()));
    }
    
    void SplashScreenSample::loadMainScreen()
    {
        emit splashScreenDone();
        qDebug("******************************************************************");
    }
    

    the HPP file:

    #ifndef SplashScreenSample_HPP_
    #define SplashScreenSample_HPP_
    
    #include 
    
    namespace bb { namespace cascades { class Application; }}
    
    class SplashScreenSample : public QObject
    {
        Q_OBJECT
    public:
        SplashScreenSample(bb::cascades::Application *app);
        virtual ~SplashScreenSample() {}
    
    public Q_SLOTS:
        void loadMainScreen();
    
        Q_SIGNALS:
            void splashScreenDone();
    
    };
    
    #endif /* SplashScreenSample_HPP_ */
    

    It seems that the alias 'splashSample' is not accessible in the onCreationCompleted signal. Is this the case? Is it possible to connect to a signal when the QML document is created?

    Thank you very much.

    You must call setContextProperty before calling createRootObject

  • Manipulate the object in another QML file

    I have a drop down menu with some functions that modify sldiers Beach

    onTriggered: {}

    Slide1.toValue = 10

    }

    It works fine, but when I move the piece that has the cursor in another qml file and include it like that...

    {MyInclude}

    }

    It stops working. Someone knows why, or how to fix it?

    One option is to give an id to MyInclude:

    MyInclude {
      id: myInclude
    }
    

    And reference it like this:

    myInclude.slide1.toValue = 10
    

    But it is better to create an alias of the upper level in MyInclude.qml property to define a public interface. Pseudo-code for MyInclude.qml:

    Page {
      property alias toValue: slide1.toValue
      ...
      Slider {
        id: slide1
      }
    }
    

    These alias properties can be referenced like this:

    myInclude.toValue = 10

    This is not limited to the alias properties, they can be of any type (int, var, etc.).

  • Determine the owner of the QML object attached to C++

    I have a C++ class that I exposed to QML the usual way, and I'm tying to control QML. The problem is that it cannot be instantiated without setting. This is exactly the same that how LayoutUpdateHandler works, but I just can't understand how this class manages about who controls it is attached to.

    The LayoutUpdateHandler constructor takes a pointer to a control as an argument. There is a constructor without arguments, but the docs say that if you use it, there is no way to define the target control later, do the actually useless LayoutUpdateHandler. Here is a typical use of QML:

    Container {
       attachedObjects: [
          LayoutUpdateHandler {
             onLayoutFrameChanged: {
                // ---Do some stuff
             }
          }
       ]
    }
    

    Don't forget that LayoutUpdateHandler MUST have the target of control set when it is instantiated, it can be done later. Somehow the code above works, and the class instantiated with the parent container as the argument to the constructor object. Now I need to do the same thing with my own class, but I can't understand how to move on the instantiation of the parent control. No matter what I try the argument never happened and only the parameterless constructor is never called.

    Anyone have an idea how it works and how I can get the QML to instantiate my class with the parent control passed as argument?

    You're not the only dev who has tried to do.  I did it too and have been successful. You are on the right track.

    Your class must inherit from BaseObject and override its classBegin() function.  This function will be called after your class has been instantiated, and her mother has been defined.

    For example, I'm doing something like this:

    class MyClass : public BaseObject
    {
    public:
        explicit MyClass();
        explicit MyClass(Control *target)
        virtual ~MyClass();
        virtual void classBegin();
    private:
        void setTargetControl(Control *target);
    };
    
    MyClass::MyClass() : BaseObject(0)
    {
    }
    
    MyClass::MyClass(Control *target) : BaseObject(target)
    {
        setTargetControl(target);
    }
    
    MyClass::~MyClass()
    {
    }
    
    MyClass::classBegin()
    {
        BaseObject::classBegin();
        if(parent()) {
            Control *target = qobject_cast(parent());
            setTargetControl(target);
        }
    }
    
    MyClass::setTargetControl(Control *target)
    {
        // Do your actual initialization here, which requres the target control.
        // In this case, the target control is the control that has this as part of
        // its attached objects block in QML-land
    }
    
  • Exponent of the QML C++ objects

    Hello

    I am new to qml and BlackBerry. What I want to do is basically described in this link:

    http://developer.BlackBerry.com/native/documentation/Cascades/dev/integrating_cpp_qml/index.html#exp...

    under "C++ objects exposing to QML.

    I did everything as described in the link. The point where I'm stuck is how to get out of here

    MyCppClass *cppObject = new MyCppClass();
    qml->setContextProperty("cppObject", cppObject);
    

    here

    Label {
      text: "Value of cppObject: " +  cppObject.value
    }
    

    When I know the code I need to create an instance of my class in the main.cpp file [MyCppClass * cppObject = new MyCppClass();] then setContextProperty to make it able to expose values to qml [qml-> setContextProperty ("cppObject", cppObject)]; and I can get the value by writing "cppObject.value" in my qml file.

    However, I get this result in the Console:

    ReferenceError: Can't find variable: cppObject

    I need to add something in the qml code so that the functions defined in C++ can be used in qml?

    I hope that these are enough information to help me here.

    All understood why I got this error.

    After you have created an instance of the class

    TMinutesContact *MinutesContact = new TMinutesContact();
    qml->setContextProperty("MinutesContact", MinutesContact);
    

    I need to set up

    AbstractPane *root = qml->createRootObject();
    
    app->setScene(root);
    

    to fill the contacts added with my duties of the class 'MinutesContact '.

    I don't know yet what exactly setScene does so that it now works.

    The App I'm trying is essentially over. The only thing missing was to implement you can get data of the qml code C++ objects. I am familiar with C++, but qml is new to me. So first of all, I had to struggle with all this code in this app.

    For all postal code containing in this app would be too much. And I don't know if I'm already good enough to choose just the necessary part that is important for my problem.

  • QML does not recognize the custom parameters of the signal object.

    Here is my sample code to test by passing an object custom c ++ qml.

    My custom object:

    class TestObject {}

    public:

    QString testString;

    TestObject() {testString = 'Hello' ;}

    };

    ...

    signals:

    void testErreur (TestObject * testObject);

    I declare it and send the singal of c ++

    Q_DECLARE_METATYPE (TestObject);

    ...

    qRegisterMetaType('TestObject');

    ...

    issue of testError (newTestObject ());

    and expect to receive the onTestError with the testObject setting

    He compiled and can receive the onTestError in qml slot, but it generates an error running this

    QMetaProperty::read: Unable to handle the kind of data not saved ' TestObject * "property"QDeclarativeBoundSignalParameters::testObject ".

    Asset:///testSreen.QML:123: error: unknown method parameter type: TestObject *.

    I did a couple of hours of looking on the forum but found no solution.  Hope that developers who have experience on the similar question can help out.

    Thank you

    Tyler

    Thanks Andrey,

    I changed it to Q_DECLARE_METATYPE(TestObject *); but still have the same error.

    The code that I showed is in fact to reduce the problem.  The actual design is to have a c ++ based customControl in the qml and I plan receive the signal and proceed the testObject to my c ++ customControl and release it there.

  • Problem with the C++ object to qml exponent

    Hello, I followed the instructions by Qml and C++ integration but got stuck at a certain time.

    Here is my code:

    // applicationui.cppPage* ApplicationUI::doLoadPageDetails(){
    
        qmlRegisterType("myHtmlPage", 1, 0, "HtmlPage");
    
        QmlDocument *qml = QmlDocument::create("asset:///PageDetails/PageDetails.qml").parent(this);
        qml->setContextProperty("app", this);
    
        HtmlPage *htmlPage = new HtmlPage();
        qml->setContextProperty("htmlPage", htmlPage);
    
        htmlPage->setHtml("*some html code*");
    

    This function creates a Page with a container that contains a WebView. Here, I want to fill the string saved as htmlPage.html.

    I created the RPC classes as described in the link and they work. When I check the htmlPage-> html() in C++, I get the string I wanted.

    Now, my problem is how to get this string for qml.

    Here's what I do:

    import myHtmlPage 1.0....Container {
    ....
            ScrollView {            visible: true
                WebView {
                    attachedObjects: [
                       HtmlPage {
                            id: htmlPage
                        }
                    ]
    
                    id: webViewScrollable1....
                    html: "" +
                    "" +
                   "*style options*" +
                    "" +
    
                    htmlPage.html +  //<----- this should give me the string I saved in C++ under htmlPage->html()
    
                    "" +
                    ""
                }
            }
    

    But nothing is displayed on the page. But why? I forgot to link something?

    I think you're getting confused in the difference between a property and recording a QML component.

    You do both.

    When you attach an object to a QML file, you create an instantiation of the object at this time, when you set a context property that you you already created that object and are just passing a reference to this.

    So when you join HtmlPage in your QML file you create a new object and does not reference that you have created in your program C++ part, so no text.

  • 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

  • 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.

  • Read the result of a SystemDialog in QML

    I have a SystemDialog as an object attached in QML:

    attachedObjects: [
      SystemDialog {
       id: dialog
      }
    }
    

    I want to read the result (ok or cancel pressed):

    dialog.title = "some text"
    dialog.body = "more text"
    var result = dialog.exec();console.log("dialog result: " + result);
    

    In my main application, I included the types:

    qmlRegisterType("bb.system", 1, 0, "SystemDialog");
    qmlRegisterUncreatableType("bb.system",1,0,"SystemUiResult", "");
    

    Console.log gives me still undefined as a result. What Miss me?

    I've found a workaround:
    If (dialog.buttonSelection () == dialog.confirmButton) {}
    ...

  • JS function as a type of page in QML property

    Hi all

    I'm trying to create useful js 'class' for my blackberry application and save here some information about qml object here is the example of such file js:

    /* * my js */
    
    function Utils(devInfo){ this.devInfo = devInfo; this.text = "test text";
    
     this.getInfo = function(){ return this.text; };}
    

    I want to group some utils functions here and use this js in qml file object, but I don't want to create "Utils" every time, I would like to have a single instance of page qml. I tried to use properties:

    import bb.cascades 1.3
    import com.example.bb10_samples_states 1.0
    import "myscripts.js" as Scripts
    
    Page {
        property variant utils : new Scripts.Utils(deviceInfo)
    
        Container {
            Label {
                id: myLabel
                text: "Hello World"
            }
    
            onTouch: {
                var newLabeltext = utils.getInfo(); // freezing
                myLabel.text = newLabeltext;
            }
        }
    
        attachedObjects: [
            DevInfo{
                id: deviceInfo
            }
        ]
    }
    

    * DevInfo is registered object c ++

    I got the following in the notecard event error message:

    "asset:///main.qml:15: TypeError: result of expression 'utils.getInfo' [[object Object]] is not a function."

    If I do not use the property and only with variable work, everything is ok. The following code works correctly:

    import bb.cascades 1.3
    import com.example.bb10_samples_states 1.0
    import "myscripts.js" as Scripts
    
    Page {
        //property variant utils : new Scripts.Utils(deviceInfo)
    
        Container {
            Label {
                id: myLabel
                text: "Hello World"
            }
    
            onTouch: {
                var utils = new Scripts.Utils(deviceInfo);
    
                var newLabeltext = utils.getInfo();
                myLabel.text = newLabeltext;
            }
        }
    
        attachedObjects: [
            DevInfo{
                id: deviceInfo
            }
        ]
    }
    

    In general, I don't know where I can store object js in qml page to access my functions utils without need to create each time. Any ideas?

    I think I found the answer

    According to this link, there is no global js object and every instance of component QML has own unique copy resources imported from JS:

    ...

    Code-Behind implementation resources

    Most of the JavaScript files imported into a document QML are implementations with State of the QML importation document. In these cases, each instance of the QML object type defined in the document requires a separate copy of the JavaScript and State objects to behave properly.

    The default behavior when importing the JavaScript files must provide a unique and isolated copy for each instance of the QML component. If this JavaScript file any resources or modules with a statement .import, its code will be executed in the same scope as the instance of the QML component and therefore can access and manipulate objects and properties declared in the QML component. Otherwise, it will have its own unique scope, and the objects and properties of the QML component should be passed to the JavaScript file as parameters functions if they are required.

    ...

    http://Qt-project.org/doc/Qt-5/qtqml-JavaScript-resources.html

    So it seems there is no need to implement the model of sigleton or store JS resources in the QML document. I changed my code as follows:

    /**
     * js
     */
    var utils = {
      devInfo : null
    };
    
    function init(deviceInfo){
      utils.devInfo = deviceInfo;
    };
    
    function getText(){
      return utils.devInfo + " done.";
    };
    

    and qml:

    import bb.cascades 1.3
    import com.example.bb10_samples_states 1.0
    
    import "myscripts.js" as Scripts
    
    Page {
        Container {
            Label {
                id: myLabel
                text: "Hello World"
            }
    
            onCreationCompleted: {
                Scripts.init(deviceInfo);
            }
    
            onTouch: {
                myLabel.text = Scripts.getText("Tra-ta-ta");
            }
        }
    
        attachedObjects: [
            DevInfo{
                id: deviceInfo
            }
        ]
    }
    

    It works fine - I can store information in the variable 'utils' and work with qml js objects. Hope so, it will help someone

  • QDateTime in qml?

    Hello

    I was wondering how to import and use the QDateTime object in qml?

    Thank you!

    any reason that you need QDateTime?

    Why not use the javascript date?

    var date = new Date();

    var formattedDate is Qt.formatDateTime (date, "yyyyMMdd");. to set the date

    You cannot store a javascript date object in a qml "establishment variant" but you can simply import a javascript with a variable to store these data in a context QML.

  • CreateObject QML property binding

    Hello, I use the createObject command to dynamically create objects on a qml page, I can do that, but now I want some properties of the dynamically object objects to bind on some properties of the parent, how it is possible?

    Greetings silajm

    Try the following detour

    1 make sure you have your parent properties loan (try also to declare them as alias just to be sure)

    2 use the parent properties during the construction of the object in the format: parent.property (or same parent.parent...)

    3 createObject(explicit parent id)

    It should work. In the case where it does not have to launch your actions onCreationCompleted where I am sure that you will get parent.property.

    Try and tell us.

Maybe you are looking for

  • moving text, very slightly to align with precision

    Hello I do a menu in pages and I would like to move some of the prices on the right side, so they all line up nicely. I don't want to choose all the 'align right' as then the food not all vertically aligned. Is there a command or action that allows m

  • Need an instalation own Vista - no recovery disc

    Hello Short version: I would like to have a clean install of Vista Business disc, not only the recovery media. I paid for the license (supplied with the notebook), and Microsoft has confirmed that I am entitled to it. But it is supposed to be provide

  • Mac Pro can not read SD cards more

    Hello I need help with a strong issue with my Mac Pro, who can not read SD cards more. Gluing of any player on any USB, an SD card is not recognized more. Strange also when I put a CF card in the same drive, it works and I can see the CF card on my d

  • LabVIEW 64 or 32-bit labview?

    Hello, I have a new 6-bit pc and an old 32-bit pc, and I have to use two of them. If I install on the 64-bit 64-bit machine labview, when I save a vi, it can be opened on the 32-bit computer? With this kind of problem, do you suggest me to install la

  • I can't get windows update to run on windows 7

    I did a clean upgrade from windows xp to windows 7.When I try to update 7 I get this messageWindows Update cannot currently check the updates, you may have to restart your computer, I have done this 6 times now nothing works.When I click on the flag