c ++ bool qml undefined when exposedwith ContextProperty

In an attempt to circumvent the problem of PickerItemComponent not been able to access what anyone outside himself, I exposed a bool for QML (my application has a Bool QML, called compactMode, long story), now since I can't access that bool compactMode I tried to expose a c ++ one like this:

public:

    bool compactModeGlobal;

    QDeclarativeEngine *engine = QmlDocument::defaultDeclarativeEngine();
    QDeclarativeContext *rootContext = engine->rootContext();

    rootContext->setContextProperty("compactModeGlobal", compactModeGlobal);

It gives me the warning of "Member"compactModeGlobal"has not been initialized in the constructor.

That, of course, it won't let me spend this compactModeGlobal bool QML

I missed something important it?

In general in the ApplicationUI constructor, you would report the properties that you want to expose from C++, using Q_PROPERTY and QObject ceremony associated with the functions of getter/setter/broadcasting signal and set a context property on your document main qml like this:

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

where "this" in the call of setContextProperty() refers to the ApplicationUI object.

Edit: So, in your doc QML, you acceding C++ properties using:

SomeQMLComponent {
    someQMLProperty:  _app.someCppProperty
}

Tags: BlackBerry Developers

Similar Questions

  • Bool becomes QString when QSettings load

    I met a problem when storing bool values in QSettings. It looks like a bug to me, but maybe I'm missing something?

    I have this piece of code:

    QSettings* settings = new QSettings();
    qDebug() << "test setting is of type " << settings->value("test", false).typeName();
    settings->setValue("test", true);qDebug() << "now test setting is of type " << settings->value("test", false).typeName();
    

    In the first round, it will print

    test parameter is of type bool

    test setting is now of type bool

    After that, it will print

    test parameter is of type QString

    test setting is now of type bool

    In the first round, there is no stored definition, it takes the default value spent, but after the setting has been set once, it seems that it is stored as a QString and load as a QString on the application next run.

    It is ruin a lot of things especially during the passage of the QVariant to QML.

    My ugly solution right now is to make a

    settings->setValue('test', settings->value('test', false).toBool())
    

    the launch for each Boolean parameter that I have.

    Anyone else seeing this?

    This behavior is expected although not very intuitive.
    QSettings stores type information in ini files. Always ask the specific type when accessing QSetting using the. toBool(), toInt(), toString() etc.

    I think it is more correct than the use of the workaround above because there is no guarantee on how QSettings stores data internally.

  • Since the installation of Firefox 4, I get this message "TypeError: components.classes['@ [cid] is undefined" when a window should open. Also saw print and print no longer work correctly.

    Since the installation of the latest version of Firefox, this message "TypeError: components.classes['@ [cid] is undefined" appears in a box when should open a new window. In addition, what you see in the Preview Print print, is not which prints.

    Recovering important data over an old profile

    https://support.Mozilla.com/en-us/KB/recovering%20important%20data%20from%20an%20old%20Profile

    Check and tell if its working.

  • How to stop pushing him to a QML Page when already in this Page

    Hello

    Main.qml I have the following question of action menu that displays SettingsPage.qml.

    hand. QML:

    NavigationPane {
        id: nav
    
        ...
    
        Menu.definition: MenuDefinition {
            actions: [
    
                ...
    
                ActionItem {
                    title: "Settings"
                    onTriggered: {
                        console.log("entering settings page");
    
                        var settingsPage = settingspagedef.createObject();
                        Qt.nav.push(settingsPage);
                    }
                },
    
                ...
    
                ] // end of actions list
    
         } // end of MenuDefinition
    
        ....
    
        Page {
    
             ....
    
        }
    

    And the SettingsPage.qml is a QML file that contains only the item page (and not in a NavigationPane). Thus, in settings page, another page of settings is pushed on top of the current page of settings when you click the action item "Settings." How can I prevent pushing to SettingsPage.qml one another when there is already a settings page? Thanks in advance.

    I prefer to remove the knob to Settngs completely rather than turn it off when I do not want my user to have access to it. My application says the menu of application as follows:

    MenuDefinition {    id: appMenu
        settingsAction: _settingsAction
        helpAction: _helpAction
        attachedObjects: [
            SettingsActionItem {
                id: _settingsAction
                onTriggered: {
                }
            },
            HelpActionItem {
                id: _helpAction
                onTriggered: {
                }
            }
        ]
        actions: [
        ]
        function restoreSettingsAction() {
            settingsAction = _settingsAction;
        }
        function restoreHelpAction() {
            helpAction = _helpAction;
        }
    }
    

    Now of QML, you can do this:

    // ---Remove the application menu Settings button
    appMenu.settingsAction = null;
    
    // ---Restore the application menu Settings button
    appMenu.restoreSettingsAction();
    

    ... and you can do the same thing with the help button if you wish. Note that if you have any other button in your menu of the application they will probably move in the menu if you delete/restore buttons settings or help.

    burakk wrote:

    Yes, I mean the menu of the Application.

    Your code turns off the entire menu. What happens if I don't only want the settings menu option? I guess I have to disable the part of the action of the main.qml. Is there another way to achieve the QML (main.qml) other action element other than Qt object implementation?

    onCreationCompleted: {}
    QT.nav = nav;
    Qt.catList = categoriesList;

    }

  • Photoshop undefined when you try to change the menus

    When you try to change a menu display menu I get "unable to run the script at line 0.  Photoshop is undefined. "What should I do to fix this?

    I had no problem with PS CC EN CS6.

    It's the usual correction:

    "Edit Menu in Photoshop" does not?

  • Error: "Eception TypeError: cannot read property 'getNumFrames" undefined "-when I test Flash/HTML5 in the browser

    I work in Flash / HTML5. When I publish directly from Flash, my project works very well. However if I open the HTML file directly in a browser, (I tested in Chrome and Safari on a Mac) I get this error message: easeljs - 0.8.1.min.js:13 Eception TypeError: cannot read property 'getNumFrames"of undefined a.load @ preloadjs - 0.6.1.min.js:12

    A google search suggested that the code tries to run before the document was loaded - so "undefined". However, I can see that the body of the HTML file tag seems to deal with this (I think) < body onload = "init (); »  ... The init() being the function that includes the Chargers how to control the loading of the file is made etc...

    Also, I get the error:

    XMLHttpRequest cannot load file:///Users/MyLocalPathToMyProject.../images/MyProject_atlas_.json. Original cross applications are only supported for Protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resources.

    Who could be responsible for the "undefined".

    Everyone knows about this problem? Can we simply cannot test it locally? Does anyone have a solution?

    Sprite sheets do not work from the local file system. Go to the publication settings and uncheck the sprite sheets.

  • Error "TypeError: components.classes['@ [cid] is undefined" when opening of Firefox - every time that it is open!

    Since the installation of Firefox 4, I get this error message "type: components.classes['@ [cid] is undefined" whenever Firefox is open and trying to access some Web sites. Very aggravating!

    This indicates that you are using an add-on that is not compatible with Firefox 4. To find out how to solve this to find out what is causing the problem, see https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Effects Spry DoFade come undefined when it's on the web

    Hello everyone and thank you for taking your time to read my request.

    I'm new in the world of web design and only started a few days ago, so I have no doubt a lack a lot...

    If the address of the Web site:

    http://florianps.byethost7.com/

    So, here's my problem, I tried the pictures on my pages before I use as links to fade (from 50%) when the user's mouse go on them.

    So I watched a few tutorial and discovered on the things of behaviors, which sounds really easy, but turned out to be a nightmare on which I have now spent two days and can not know where the problem comes from...

    When I do a preview in dreamweaver, of course, all is well, and it works perfectly.

    But once the pages are downloaded on the serv (a free server like I'm still in a trial period) behaviors do not work anymore...

    This is what firefox tell me:

    (you don't have to worry about CSS, they seem really in trouble)

    prob1.jpg

    Which leads me to the following line:

    problem2.jpg

    So, here I am, I really hope that some of you had the problem before and could tell me how to resolve this issue!

    Thanks for reading anyway, hope to hear from you!

    Sincerely,

    Anarsheep - Flo

    End of the last year, Adobe has discontinued the Spry framework.  So it is unlikely that you will see in the future of Spry release of DW.  I no longer use Spry for what it is.

    Opacity can be controlled very well with simple CSS code and a couple of MS filter for older IE browsers.

    http://www.w3schools.com/CSS/css_image_transparency.asp

    Nancy O.

  • LoadVars still undefined when viewing downloaded movie

    Hello

    I created a flash animation that has a 'contact us' form, which sends the name, email, phone number and comments to an ASP.NET web page that acts as a relay of e-mail. Is it is able to communicate with the ASP page, and then it displays a 'success' message If it is impossible to contact the server or if the ASP page returns an error, then it displays a message "error".

    When I test the movie on my computer (either directly from Flash or a Web page on my hard drive), there is no that it is supposed to do: send contact information to the Web server and then displays a message "success" or "error", but when I download the movie on a server (even on a local server) it is always "not defined". I already tested it on 4 different servers (including the local server) and it is always the same.

    Miss me that causes this behavior?

    Thanks for any help that you could provide.

    1. place last
    email.sendAndLoad (" http://www.promocasa.com.mx/tools/formaCorreo.aspx", )
    emailResponse, 'GET');
    You have a potential synchronization problem where emailResponse.onLoad =
    function(Success:Boolean) is not assigned until the response is saved.
    something = function is an assignment of the time of execution and should be treated
    before that it could be used.

    2 have you tried 'POST' instead of 'GET '?

    3 is a Flash animation on the same domain as www.promocasa.com.mx. Otherwise you
    need a crossdomain.xml file.

    4. try a Flash animation very basic which simply sends and receives some static
    data on your server.

    5 Add traces to the emailResponse.onLoad
    trace ("emailResponse.onLoad - success:" + success);

    6. be sure that you don't have an older version cached of Flash animation in your
    Web browser. A quick way is to temporarily rename and download.

    7. not sure on your scope because it works locally, but for a test set
    var email: LoadVars = new LoadVars();
    var emailResponse:LoadVars = new LoadVars(); on the chronology and commentary
    inside of the one (click)

    --
    LON Hosford
    www.lonhosford.com
    Examples of Flash, Actionscript, and Flash Media Server files:
    http://flashexamples.hosfordusa.com
    Number of happy bits exempts your way!
    "saldillo" wrote in message
    News:ed70m3$6ei$1@forums. Macromedia.com...
    > Well, Yes, I already did.
    >
    > I have created a basic HTML page that has a bunch of fields hidden which
    > represent
    > the data sent by the flash movie. I downloaded on the same server
    > where
    > I downloaded the SWF file to see if she had nothing to do with the server, but
    > Unfortunately,.
    > When I press the button submit on the HTML page it displays the message OK
    > that is
    > sent by the ASP page, and I received the email fine.
    >
    > I never receive the email when I press the button submit on my downloaded
    > SWF
    > film, which leads me to believe that the ASP page does not receive the
    > information.
    >
    > I enclose my AS code, I forgot to do it in my original posting.
    >
    > Thank you for your answers.
    >
    >
    >
    > on {(click)
    > var email: LoadVars = new LoadVars();
    > var emailResponse:LoadVars = new LoadVars();
    >
    > / / This is the data that the user entered in the contact form.
    > email.txtNombre = _parent.txtNombre.text;
    > email.txtEmail = _parent.txtEmail.text;
    > email.txtTelefono = _parent.txtTelefono.text;
    > email.txtComentarios = _parent.txtComentarios.text;
    >
    > / / My ASP page should work for any SWF movie so I put here for each
    > film which
    > / / sends data to the server. Once I get this work in the way that he
    > should, I'll load the info from a text file to
    > / / avoid this hard coding in the film.
    > email.txtEmailReceptor = "[email protected]"; Who should
    > receive email
    > email.txtEmailEmisor = "[email protected]";
    > email.txtDesarrollo = "Residencial Barcelona." Which Web page

    > origin
    > This application
    > email.txtAsunto = "BARCELONA: Forma contacto del sitio web Barcelona."
    ' > Residencial "; Object
    > email.txtMensaje = "Se ha petici una received? n information? n del sitio
    > web
    > Barcelona hotel. « ; //
    > email.sendAndLoad (' http://www.promocasa.com.mx/tools/formaCorreo.aspx', )
    > emailResponse.
    (> 'GET');
    >
    > emailResponse.onLoad = {function (success:Boolean)}
    > var strSuccess:String = '? '. Gracias por you inter? s! One of our
    > asesores
    > recibi? You petici? n y is pondr? by contacto para atenderte. « ;
    > var strError:String = "Lo sentimos. Hubo a t error? about enviar al Técnico
    > information? n. Por favor cont? such por ctanos? Fono para poder atenderte.
    > Exonerated
    > las molestias. « ;
    > var strMensaje:String = this.mensaje;
    >
    > If (success) {}
    > _parent.estado_txt.text = strMensaje; Print the message to a
    > dynamic text field called 'estado_txt '.
    > _parent.nextFrame (); This deletes my entry form and shows the
    > estado_txt field.
    > }
    > /*
    > If ('OK' == strMensaje.substr (0.2))
    > _parent.estado_txt.text = strSuccess;
    > other
    > _parent.estado_txt.text = strerror(errno);
    >
    > _parent.nextFrame ();
    > */
    > };
    > }
    >

  • Two documents qml, a normal application, one to share the preview card generator

    Hey. Read and experiment - what is the proper way to load a qml document when the application is opened normally and the other when the application is invoked as a previewer of card using a share action? I guess you can't mess with main and the createqmldoc and the setscene must be in the constrcutor.

    How could I go about this?

    Appreciate the help,

    See you soon

    Justin D.

    We use startupMode to check how the application was launched

    switch (invokeManager->startupMode()){
    

    in the case of ApplicationStartupMode::LaunchApplication we init the complete user interface, otherwise wait us signal invoked and go from there.

  • QML Audio problem

    This is QtMultimedia audio qml. Do you have someone at - it using problem audio qml. When I want to jump to the next song as the code example below using audio qml, after playing on dozens of song perfectly all of a sudden she stops just. The code below works on symbian but in BlackBerry stop to jump to the next song after playing on a dozen of song(random sometimes) signals onStopped Manager seems to just stop working. Is there a bug problem audio qml with BlackBerry. The internet search got no results.

    I use console.log to the event log when the song ended and the song started and every time the song skip to the next song, both log console, but when the question produce two stop the event record, which is also when the decision to jump to the next song. OnError has not also record any error on console so not even sure what is happening.

    Audio {
             id: audio
    
             //LOGGING ANY POSSIBLE ERROR
             OnError: {
             Console.log("Error: ", error)
             Console.log(errorstring)
    
             // LOGGING BOTH ENDOFMEDIA AND NEXTSONG WITH CONSOLE.LOG
             OnStopped: {
                 Console.log("endofmedia")
                 if (status == Audio.EndOfMedia) {
                 Console.log("startplay")
                 nextsong()
                 }
             }
         }
    

    The problem is resolved. It's because of the components old symbian. Although I know not even how a symbian component can affect component Qt Quick but recompile component symbian has solved the problem. Here is the link to the cases where any interested person

  • To access the classes of CPP in qml.

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

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

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

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

    Great Question!

    Local objects:

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

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

    Global objects:

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

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

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

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

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

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

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

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

  • Can't access (outside) QML elements of ListItemComponent

    Hello

    I have a problem to access the variables of a ListItemComponent in my QML.

    My QML is a container that contains a ListView with several ListItemComponents.

    I updated my QML list as a contextProperty data model:

    QML-> setContextProperty ("_dataModel", homeDataModel);

    My data model has Q_INVOKABLE I want to call from my QML.

    The problem is that, in ListItemComponent, I can not access or "_dataModel", or all the elements that are outside the component itself.

    I found a solution that would use extended Qt such as:

    onCreationCompleted: {}

    Qt.homePage = home page;

    Qt.homeList = homeList;

    }

    Using it, I could access variable outside of my ListItemComponent. The problem is that the scope of the Qt interval is too large. In effect, if I create multiple instances of the Pages using the QML, Qt.homePage/Qt.homeList will have the value given by the last instance of Page. This isn't a good solution for me because I use it to access the dataModel of the list and the dataModel has an associated NavigationPane.

    Anyway, you know other solutions to access my data from my ListItemComponent model?

    Thank you

    I just hit this same question today...

    You can get a handle to the item list to the view and from there, get what you need...

    In my component list item:

                    listItemComponents: [
                        ListItemComponent {
                            Container {
                                id: itemRoot...
    

    You can then refer to the root element and finally the view... Here is a button that is located in my list item... Dumping a bunch of things and call for trigger on the list view...

                               Button {
                                    text: qsTr("Go!")
                                    horizontalAlignment: HorizontalAlignment.Center
                                    onClicked: {
                                        console.debug("ListItemData: " + ListItemData);
                                        console.debug("itemRoot: " + itemRoot);
                                        console.debug("itemRoot.ListItem: " + itemRoot.ListItem);
                                        console.debug("itemRoot.ListItem.view: " + itemRoot.ListItem.view);
                                        console.debug("itemRoot.ListItem.view: " + itemRoot.ListItem.view.dataModel);
                                        console.debug("itemRoot.ListItem.view.trigger: " + itemRoot.ListItem.view.triggered(ListItemData.indexPath));...
    
  • To access the properties of QML context through several QML files

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

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

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

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

    hand. QML

    {

    ...

    {ListItemComponent}

    type: 'point '.

    LargeThumbItem {

    }

    }

    ....

    }

    LargeThumbItem.qml

    {

    ....

    WebAPI.getImagePath (...)

    ...

    }

    I do the usual configuration...

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

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

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

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

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

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

    Then in LargeThumbItem.qml for example

    {WebImageView}

    ...

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

    ...

    }

  • call the function onCreationCompleted c ++ in qml

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

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

    For example:

    {Page}

    onCreationComplete:

    {myFunction() ;}

    Button {}

    ojbectName: "button1".

    }

    }

    MyFunc access using findChild button1.

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

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

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

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

Maybe you are looking for

  • love at first sight

    After giving a presentation using my Macbook Air on a video-projector (connected on the thunderbolt with a VGA adapter port), my Macbook no longer recognizes my Apple Thunderbolt to the home screen. If I connect another Macbook to the Thunderbolt dis

  • Model: m6-1045dx laptop, cp1525nw printer wireless

    Laptop: model: m6-1045dx B5S08UA #ABA Moving up to 15 years in router technology.  A router dual-band would work with both of these?   What I need to look for if I buy a new router fancy then try to connect with older hardware?  Even a WII? Know any

  • Google blocks my access to Google sites!

    Pavilion g6 1201 tx. Win 7 Home Basic 64 bit SP1. Well, I was looking on Google on a beautiful day, and all of a sudden, Google warned me! I was shocked. He said, he was getting many requests from my IP address, and they need to check if the robot is

  • Im trying to download my cv, but it only takes doc or docx

    I have windows xp im trying to download my cv, but the site does that docx doc what should I do?

  • Third Patry all my photos have been deleted, can we recover those?

    I was recently left my apartment and my computer was left in the apartment for a few days. When I came back, I found that all my photos have been deleted and the Recycle Bin has been emptied. is there a way I can recover these files?