Accessing the context property of main.qml to a custom list in a file item separate qml
Hi all
Sorry if this is already covered somewhere.
I currently have an application with a list view in my main.qml. I put a context property for my class app c ++ to be "app" in my main.qml. My list uses a custom list item that is defined in a file separate qml. The custom list item has a popup menu. In this context menu, I want to call Q_INVOKABLE functions that are part of my class from the main application in C++. What is the best way to be able to do? Should I just set the context property on my file qml of list item custom like I do with my main.qml or is there a better way?
Thank you
I think that this has been repeated several times, but as it is not really intuitive:
a listitemcomponent lies in a different context, it cannot access the context property of the qml file.
You can use the reference to the listview to reach outside, see https://developer.blackberry.com/cascades/reference/bb__cascades__listview.html ListItem.view
Tags: BlackBerry Developers
Similar Questions
-
Can not access the context property of the Interior of the ListView checkbox - onCheckedChange event
I have a context property called "app" that connects to my C++ application. My listview has a box with onCheckedChange event listener. In this method, when I make a call to the C++ side. application app.runAction, the system displays not found error app.
If I move the box outside the list view, it will correctly trigger app.runAction.
Can you please take a look? Thank you!
On the side of C++ on how I set the context property.
QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);
If (qml-> {hasErrors())}
Returns false;
}QML-> setContextProperty ("app", this);
navigationPane = qml-> createRootObject
();
If (! navigationPane) {}
Returns false;
}QML side
NavigationPane {}
ID: nav{Page}
ID: mainPage
{Of container{To ListView
listItemComponents:]
{ListItemComponent}
type: 'point '.
{Of containerCheckbox {}
Determine whether the check box should be checked
According to a value in the data model
checked: ListItemData.checked
onCheckedChanged: {}
app.testAction ();
}
}This is a scope issue... I really hope the devs find a way to fix it properly apart from this ugly solution:
You can solve this problem by setting your app variable in the global object Qt
NavigationPane { id: nav onCreationCompleted: Qt.app = app Page { id: mainPage Container { ListView { listItemComponents: [ ListItemComponent { type: "item" Container { CheckBox { // Determine whether the CheckBox should be checked // according to a value in the data model checked: ListItemData.checked onCheckedChanged: { app.testAction(); Qt.app.testAction(); } }
all code in a ListItemComponent will suffer from this 'framing' question
-
Cannot use the context property in a page created from an another qml with createObject()
gestureHandlers: [ TapHandler { onTapped: { var page = infoPage.createObject(); taskCont.ListItem.view.pushNewPage(page); //this pushes page to navigationPane (function at top of qml) } attachedObjects: ComponentDefinition { id: infoPage; source: "asset:///taskInfo.qml" } } ]
This is how I created the page of 'taskInfo. In the PRC, I registered a context property that I am able to access it from the current page but not in 'taskinfo. "gestureHandlers: []" is "listItemComponents".
I expect to access the object of 'taskInfo' is because I am able to access it from another page created the same way.
Here's how to register the context property.
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); mainModel = new ListModel(); qml->setContextProperty("Model" , mainModel);
OK, I found my problem.
The reason why he doestn can't work because the page is pushed out "main.qml".
This is part of my main.qml
Container { id: main_content TaskList { } }
TaksList is another qml file. When I createObject from this qml file, somewhy context property is not trafered to this object.
I've found a workaround. I created a function in main.qml and only now I create object, so the contextproperty is transferred
-
To access the classes of CPP in qml.
I have set up to access the classes of PCB in qml in two ways: -.
1. create an attached object and the id of the class of CPP special and then access via the id.
2. fix the CPP on the qml class before pushing the page using the setContextProperty.
I wanted to know exactly when to use these two methods. There a difference in terms of scope and memory. Please explain.
Great Question!
Local objects:
Attached to objects, or who inherit from classes of cascades, is the simplest way to expose c ++ objects that relate to user interface elements. This is what you use if you want this object to BELONG to this context qml. It is created by the qml context when createObject is called (your qml file is loaded) and destroyed with the user interface objects. You can create many of these objects, anywhere you need. However, if you want to expose global properties, it is probably not a good approach.
The only time you would use objects attached to global stuff is if you expose a singleton class to allow qml set locations to manage signals (OrientationHandler is an example of that, without an OrientationHandler object, that you have nothing to connect).
Global objects:
Context properties can be considered global variables for a particular context, but with inheritance: context properties are passed to the contexts of the child. These objects are the PROPERTY of c ++, must be created before the creation of the object (createObject is called) and must remain valid for the lifetime of any context, they are placed in, but then destroyed is no longer necessary.
The disadvantage of context properties changing them can be expensive. If you set a context property after the createObject call (that is to say an object exists that was created from this context), then all links in javascript in this context will be re-evaluated. However, you can mitigate this issue by exposing an object that contains the value as a property, so that links to branch on change of signals well if necessary.
Inheritance is where shine context properties. There is a context root, which is in this context of default parent for new contexts. If you set a context property of the root context, it is available everywhere in any document qml. Here is an example of how do:
QmlDocument::defaultDeclarativeEngine()->rootContext()->setContextProperty("app", myApp);
Note: when I speak of createObject, I'm talking about QDeclarativeContext::createObject. It is called internally by QmlDocument::createRootObject.
For more information on the Qml contexts, see http://qt-project.org/doc/qt-4.8/qdeclarativecontext.html
For more information about the inner workings of qtdeclarative, see http://qt-project.org/doc/qt-4.8/qdeclarativeengine.html and http://qt-project.org/doc/qt-4.8/qdeclarativecomponent.html
http://Qt-project.org/doc/Qt-4.8/qtbinding.html is still relevant as well
-
How to access the functions on my main SWF of my external SWF?
Hello someone can help me how to access the functions on my main SWF file of a loaded SWF file?
Forget using parent. Send an event to the place.
btn3.addEventListener(MouseEvent.CLICK, btnClickHandler); function btnClickHandler(e:MouseEvent):void { dispatchEvent(new Event("categoryClick"); }
In your main swf file, listen for the complete event on the Loader.contentLoaderInfo.
In the complete event handler, add an event listener for the categoryClick (or you have chosen to call it) on the loaded swf file.
// event handler triggered when external swf is loaded function loaderCompleteHandler(event:Event) { (event.currentTarget.content as MovieClip).addEventListener("categoryClick", categoryClickHandler); } function categoryClickHandler(event:Event):void { trace("category button clicked in loaded swf"); }
And remember, whenever you use root or parent, God kills a kitten.
-
Can not access the context in QML property
So I have an arraydatamodel in the CPP file, I use qml-> setContextProperty (...) to set it up to allow QML to access, the strangest part is, no matter if I put it in navigationPane Page or a container, it keeps saying can't find not variable, but in the same QML in ListView, they can access it without a problem. The other weird part, it is an another QML is able to access it in the tag of the page, the same model.
By default of the Jun 02 9000 REVIEWS asset:///main.qml:24 09:12:59.416 com.example.IntervalTimer1.testDev_ervalTimer1a7a2c2e2.427733134: ReferenceError: can't find variable: eventsModel
By default of the Jun 02 9000 REVIEWS asset:///main.qml:110 09:12:59.416 com.example.IntervalTimer1.testDev_ervalTimer1a7a2c2e2.427733134: ReferenceError: can't find variable: eventsModelHere is my code
import bb.cascades 1.0 NavigationPane { id: navigationPane backButtonsVisible: false // Javascript definition function udpateTotalTimeLabel() { console.log("In updateTotalTimeLabel function"); var totalHour = 0, totalMinute = 0, totalSecond = 0; // To debug javascript object print function var print = function(o) { var str = ''; for (var p in o) { if (typeof o[p] == 'string') { str += p + ': ' + o[p] + '; '; } else { str += p + ': { ' + print(o[p]) + '}'; } } return str; } console.log("EventsModel: " + eventsModel.size()); for (var i = 0; i < eventsModel.size(); i ++) { var currentEvent = eventsModel.data([ i ]); console.log("EventsEvent: " + currentEvent["EventName"]); totalHour += currentEvent["EventHour"]; totalMinute += currentEvent["EventMinute"]; totalSecond += currentEvent["EventSecond"]; } if (totalHour < 10) totalHour = "0" + totalHour; if (totalMinute < 10) totalMinute = "0" + totalMinute; if (totalSecond < 10) totalSecond = "0" + totalSecond; totalTimeLabel.text = totalHour + ":" + totalMinute + ":" + totalSecond; } function onDataReady() { console.log("Received DataReady signal"); navigationPane.udpateTotalTimeLabel(); newEventSheet.close(); } Page { id: root titleBar: TitleBar { title: "Interval Timer" } ..... onCreationCompleted: { navigationPane.udpateTotalTimeLabel(); console.log("No of EventsModel: " + eventsModel.size()); console.log("In sheet creationCompleted"); mainObj.dataReady.connect(navigationPane.onDataReady); } }
In the PRC
// Default empty project template #include "applicationui.hpp" #include
#include #include #include "CountdownTimer.hpp" using namespace bb::cascades; ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // create scene document from main.qml asset // set parent to created document to ensure it exists for the whole application lifetime QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Initialize the Array Data Model for holding events this->eventsModel = new ArrayDataModel(); // For Testing only QVariantMap event; event["EventName"] = "Event1"; event["EventHour"] = "00"; event["EventMinute"] = "01"; event["EventSecond"] = "02"; this->eventsModel->append(event); // create root object for the UI AbstractPane *root = qml->createRootObject (); // Registering the QTimer type to QML qmlRegisterType ("TimerLibrary", 1, 0, "CountdownTimer"); // Setting the access for QML to member variable qml->setContextProperty("eventsModel",this->eventsModel); qml->setContextProperty("mainObj",this); // set created root object as a scene app->setScene(root); } ..... void ApplicationUI::refreshData() { emit dataReady(); } Thank you.
The fixed.
You must call setContextProperty before calling createRootObject.
-
How to access the instance property of the main class via child class
Hi I hv done 3 classes objecthandler, box and nav
NAV is child chass objecthandler, I hv make an instance of objecthandler box and now I want to access the property of box via NAV... See the code
Class Objecthandler
package code {}
import flash.display.MovieClip
import code.box
import code.nav
public class objectHandler extends MovieClip {}
public var container: box
public var navigation: navpublic void addObjects() {}
Navigation = new nav()
addChild (navigation)
navigation.addEvents)
navigation.x = 275
navigation.y = 400
container = new box()
addChild (container)
putcontainer ("default")< < works well here
}
public void putcontainer(page:String) {}
Container.OpenPage (page) < < when this function is executed it returns ("page is open"+ page)
}
}
}Class of NAV
package code {}
import flash.display.MovieClip
import flash.events.MouseEvent
import flash.display.DisplayObjectContainer
import code.box
public class nav extends objectHandler {}
public void nav() {}
}
public void addEvents() {}
homeBtn.addEventListener (MouseEvent.CLICK, releaseFun)
galleryBtn.addEventListener (MouseEvent.CLICK, releaseFun)
productsBtn.addEventListener (MouseEvent.CLICK, releaseFun)
contactBtn.addEventListener (MouseEvent.CLICK, releaseFun)
}
public void releaseFun(event:MouseEvent):void {}
putcontainer(Event.currentTarget.Name) < < showing the error over here
}
}
}You should review your logic.
It is not supposed have nav extend objectHandler and then has an objectHandler method that creates a new instance of nav.
-
Access the Text property in the class
I have problems to access the text fields .text property in my object. When I try to refer to the text box outside the service to create the text field, I get "1120: access of undefined property titleField.» Any idea is appreciated. Thank you!You have titleField declared as a variable for instance apart from this feature. (I think.) If this variable exists in your function addTitle. When it comes to your setPanelTitle that you can't simply make reference to the instance that you created earlier.
So I think you could declare titleField as an instance variable.
Or, in your setPanelTitle, you can use one of the functions getChildByName. I have not used enough AS3 it know right on top of my head, but since you have given a name - which is be the same as the name of the variable you used - you can find it by name later.
-
Cannot access the context Menu to add input/output formula node
It is a weird problem. I can't access the menu shortcut in the node of the formula. I right click on the border, nothing happens. Someone at - it will meet it before? Is there another way to add entries and exits?
I'm running Vision Builder AI and want to use a formula node in my calculator.
Found.
In the configuration settings, there is an entry that is default 'hideBDPopupMenus = True'... changed to false and the menu pop.
Thanks for your help.
Josh
-
Is it possible to access the path property of a shape by CEAP API layer?
Hello world! I recently started depeloping AE plugin and try to access the path of the forms of the CEAP API layer. Sorry in advance if my question has already been asked by someone before, but I couldn't exactly find the answer to my question so let me ask.
In a publication, I have a shape layer, and the shape layer has a vector shape, represented by the pen tool. Looks like the constitution of the lower layer.
Apparently, these streams of the layer as an anchor Point, Position, and scale are accessible by AEGP_GetNewLayerStream. However, I don't know how I can get the pointer to the form 1 and get the path to it because these valuse aren't categolized in any types of AEGP_LayerStream.
Very similar question was asked in the following link and Informatics were advised to use MaskOutlineSuite, PathQuerySuite and PathDataSuite, although these suites are to make the effect, not for CEAP plugins plugins, so I don't know if they can be used here.
http://forums.Adobe.com/thread/1068528
So could someone kindly enlighten me on this?
Thank you very much.
Hi hagmas! Welcome to the forum, where there are many existing responses
but never for exactly what you are looking for.
Firstly, each suite which is the name of functions start with ECAP, were in fact
created for the use of plug-ins of the CEAP, but most of them (including the suites you)
mentioned) can also be used in effects. (and not as you thought, the other
way around)
Indeed the shape layer flow are not indexed, and that's because then
are added dynamically by the user and can be re-ordered.
look in the "suite of dynamic flow", that helps, you will get the first
the shape layer flow and navigation well there early by getting the
broadcast the name, type, parent of the ect group...
You'll find 'content' group and in her groups "form."
and in them... you get them the picture.
Yes, it's a bit tedious, but since there is nothing in these groups order
determined in advance or guarantees, there is no other way to go (that I know of).
-
Windows broke down and I need to reinstall Vista. So I can make a backup of my favorites, but I guess that there is a file somewhere on my crashed disk that bears this detail. If so, can I copy this file and replace in my new installation of firefox. If this file exists, I would like to know the name of the file that I need to copy and that I could find it in the directory.
The anonymous gives path is for Vista not XP.
The "places.sqlite" file is the file that contains your bookmarks and history. It is located in your profile folder.
See:
http://support.Mozilla.com/en-us/KB/profiles#How_to_find_your_profile
Display the hidden files and foldersIn XP, the path is usually:
C:\Documents and Settings\UserName\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default
("xxxxxxxx" is a unique alphanumeric identifier)When you copy data from your OLD profile to your NEW profile, copy individual FILES (some require more than 1 FILE). DO NOT copy the entire OLD PROFILE folder; It will not work.
See: recovery of data from an old profile
Other topics: ~ ~ Red: you have installed the plug-ins with known security issues. You must update them immediately. ~ ~
Java Update: version 1.4.2 (~ ~ Red: very old ~ ~); current version 1.6.0.20 (important update 15/04/2010)
(Firefox 3.6 and above requires Java 1.6.0.10 and above; see: http://support.mozilla.com/en-US/kb/Java-related+issues#Java_does_not_work_in_Firefox_3_6 )
(Windows users: do the update manually, very easy.)
Check your version here: http://www.mozilla.com/en-US/plugincheck/
See: Java Update
Do the update with Firefox closed.Install/update Adobe Flash Player for Firefox: your version 10.0 r45; current version 10.1 r53 (Security important update 2010-06-10)
Check your version here: http://www.mozilla.com/en-US/plugincheck/
See: Flash update
-use Firefox to download and SAVE to your hard drive (save to the desktop for easy access)
-the release of Firefox (file > exit)
-Make sure that Firefox is completely closed (Ctrl + Alt + Delete, choose Task Manager, click the processes tab, if "firefox.exe" is on the list, made a "firefox.exe" right-click and choose end process, close the Task Manager window)
-Double-click the Adobe Flash Installer, you just download to install/update Adobe Flash
-When Flash is installed, start Firefox and test the installation of Flash here: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15507 & sliceId = 1- NOTE: under Vista and Windows 7 you may need to run the installer of plugin as an administrator by starting the installation program via the context menu if you do not get a UAC ask permission to continue (that is, nothing seems to happen). See this: http://vistasupport.mvps.org/run_as_administrator.htm
- NOTE for IE: Firefox and most other browsers use a Plugin. IE uses ActiveX of Flash version. To install/update IE ActiveX Adobe Flash Player, same instructions as above, except use IE to download the ActiveX Flash Setup.
- See also: http://kb.mozillazine.org/Flash ~ ~ Red:AND~ ~ How to change options to add Adobe to the list of allowed sites
-
Not able to access the ListItemComponent property
Hello
I've created a property of type "string" in a page qml as follows
import bb.cascades 1.0 import bb.data 1.0 import com.du.data 1.0 import du.image.slider 1.0 Page { id: homeListPage property string imagePath ........ }
IAM having a ListView in the same page qml. IAM trying to set this property as the text of a label which is a listItemComponent.
My problem is:
When Iam trying to put the text of the label (the label is a ListItemComponent) with the property and then an error pops up:
ReferenceError: Can't find variable: imagePath
It's my qml file
import bb.cascades 1.0 import bb.data 1.0 import com.du.data 1.0 import du.image.slider 1.0 Page { id: homeListPage property string imagePath Container { ListView { preferredHeight: 4 * 350 id: homeList objectName: "homeList" layout: GridListLayout { columnCount: 2 cellAspectRatio: 1.0 horizontalCellSpacing: 12 verticalCellSpacing: 12 } dataModel: homeDataModel listItemComponents: [ ListItemComponent { id: myComponent type: "item" Container { id: homeListItemContainer layout: AbsoluteLayout {} ImageButton { defaultImageSource:listItemData.imagePath } //imageview Container { layout: AbsoluteLayout { } Label { id:lab1 text: imagePath //here Iam using the proprty imagePath } } //container } //container } //list component ] // listItemComponents } //list view
Please please help me solve this problem
ListItemComponents have different context, but it is possible to access outside properties indirectly via the id of the top-level ListItemComponent element. Please see the updated code, I have marked the changes with //---UPD---
import bb.cascades 1.0 import bb.data 1.0 import com.du.data 1.0 import du.image.slider 1.0 Page { id: homeListPage property string imagePath Container { ListView { //----------UPD---------- function getImagePath() { return imagePath } //----------UPD---------- preferredHeight: 4 * 350 id: homeList objectName: "homeList" layout: GridListLayout { columnCount: 2 cellAspectRatio: 1.0 horizontalCellSpacing: 12 verticalCellSpacing: 12 } dataModel: homeDataModel listItemComponents: [ ListItemComponent { id: myComponent type: "item" Container { id: homeListItemContainer layout: AbsoluteLayout {} ImageButton { defaultImageSource:listItemData.imagePath } //imageview Container { layout: AbsoluteLayout { } Label { id:lab1 //----------UPD---------- text: homeListItemContainer.ListItem.view.getImagePath() //----------UPD---------- } } //container } //container } //list component ] // listItemComponents } //list view
-
Hello
By reading all the numeric values for all tests, I created a custom log file. Double values as reported by TestStand and viewable integrated reports look like this:
9.255963134932e + 061
Here's the CVI code that I use to read:
sprintf (keyName, "Locals.ResultList [%d]. Digital,' I have);
tsErrChk (TS_PropertyExists (seqContextCVI, errorInfo, keyName, 0, & propertyExists));
{if (propertyExists)}
tsErrChk (TS_PropertyGetValNumber(seqContextCVI,&errorInfo,keyName,0,&numproperty));
sprintf(szBuf,"%.5LF",numproperty);}
What I get in my report is the following:
92559631349317830736831783200707727132248687965119994463780864.00000
Any ideas?
Thank you
CT
Hello Cimteker,
Online, "sprintf (szBuf," %.5lf"...",you specify szBuf must be written with 5 numbers of precision, that is why your report shows 5 zeros. "). To record the values in scientific notation, you should change the formatting of sprintf '% e '.
-
Why Xcode crash when you try to access the context menu?
I'm on El Capitan 10.11.3, Xcode 7.2.1 (7 c 1002), MacBook Pro (15-inch, 2.53 GHz, mid 2009), 4 G memory
Hello TGacctg,
I'm not aware of any problem. You can post your crash report?
-
When I type medicare.gov, the site that I have has a list of the contents of hyperlinks. When you click on a link, the screen refreshes to the same list.
The page opens normally for me.
Wait a minute, the details of your system to watch;
Plug-ins installed
Shockwave Flash 14.0 r0
Shockwave Flash 12.0 r0
Shockwave Flash 11.9 r900
Shockwave Flash 11.6 r602
Shockwave Flash 11.6 r602AND
Adobe PDF plugin for Firefox and Netscape 11.0.07
Adobe PDF plugin for Firefox and Netscape "9.5.5.Having multiple versions of a program can cause problems.
Flash is infamous for cleaning is not on the old version as part of an update.
Take uninstaller from here:
Uninstall Flash Player | Windows
Uninstall Flash Player | MacReinstall the latest version.
Update your Shockwave Flash v14. http://get.Adobe.com/Shockwave/
Is the link for Flash Player: http://get.adobe.com/flashplayer/
Maybe you are looking for
-
Just saw that Thunderbird has been updated to version 38.0.1 and I found that the "+" in the message pane is missing and displays now any electronic information in this area. Previously, I was able, by using a + button at the top left corner, change
-
problem with downloads - I clicked on "do this automatically" and I get 100 new screens!
I have a new Mac - asked where I wanted my download to open. I clicked on "Do this automatically", and now I get 100 +.screens of bland and can only get it off when I close the entire computer down and now cannot download anything because of extreme
-
I have Java Console 6.0.01.03 and when I open Firefox it says I can install Version 6.0.02.03 so I say install. So when I turn off my machine and I go to Firefox it asks me to do it again.
-
Spotlight from break without deleting the index
Is it possible to pause Spotlight without erasing the existing index? Since the update to EC, I have the problem that a lot of other users is with Spotlight constantly indexing. I still want to be able to use spotlight, but want to be able to pause w
-
Cursor starts to move all over the screen. How to stop it?
Original title: cursor/mouse creeping I saw it everywhere and it could be here. How can I get rid of the 'MOUSE CREEPING SYSDROME". It is started without any particular reason you cursor around homelessness to the screen you upwards, downwards, means