I'm making a QList of a custom class called ControlIcon. I create the ControlIcons, and load them up with member variables, and then add them to the list. Here's the append code:
this->cueList.append(firstOne);
Here's the declaration of the QList:
QList< ControlIcon *> cueList;
If I break right after the append, I can see that the ControlIcon that was just added is full of members, and appears fine. I look in the list, and the ControlIcon that's been appended (and it does append a ControlIcon) has no members at all. I've made a QList of custom objects before, so I'm very confused. Could someone help?
Your custom class must be assignable, that means it must provide a default constructor, a copy constructor and a assignment operator. If they don't, weird things like this can happen.
cueList contains pointers to ControlIcon objects, but it is not responsible for creating or keeping those ControlIcon objects. How did you get the pointer firstOne? If it points to something on the stack, that object would be invalid when you try to use it later. If it was created with new, it will stay valid until you clean it up using delete.
I changed the data type of the list to be SerialController (the child of ControlIcon), which is what I was trying to add to it, and it works fine. This is really annoying, because there's other types of controllers, but I guess it will have to work for now.
Related
I have a transmogrifier pipeline to insert objects to my Zope database (importing zexp files from a directory structure). This works - the objects are created; but I don't get them added to the portal_catalog.
I added a section to add the objects to the catalog explicitly, inspired by plone.app.transmogrifier.reindexobject: I call portal_catalog.catalog_object(obj) for each item.
The objects exist, and getPhysicalPath yields the correct values, but the objects are not added. There is no error message or exception whatsoever.
I tried to specify the list of indexes (the idxs argument), but this didn't change anything. If not specified, all indexes should be filled anyway, right?
Since it looks like a transaction problem to me (no errors, but nothing stored in the catalog either), I tried transaction code (begin, savepoint, commit, and in case of exceptions abort), but it didn't help. When I call the catalog immediately after the catalog_object call (portal_catalog(path='/Plonesite/full/path/to/object')), nothing has happened, and an empty list is returned.
The catalog does contain objects; even objects of my custom datatypes (AT-based). Not even the Folder objects of my imports are indexed.
Without the objects in the catalog, my import is useless. What can I do?
Thank you!
Edit: Any hint about how to get my object trees in the catalog is appreciated! Even if it can't be integrated in my process. I need the contents cataloged ...
My custom content types are contained in the Plone Catalog Tool page selection field, but I don't know whether this is sufficient.
Edit 2:
Somehow my objects have been catalogued - the unrestrictedSearchResults method shows them! However, it can't be the desired solution to use this method all over; so I need to "un-restrict" the entries somehow.
It turned out that I have a monkey:patch (xmlns:monkey="http://namespaces.plone.org/monkey") for the Products.CMFPlone.CatalogTool.CatalogTool.searchResults method; this filters the catalog for my additional field subportal unless a special value for it is given - even in the management view ... Unfortunately, I had no way to specify this special value in that view.
Thus, the solution was to weed out all wrong values (for subportals which don't exist in the other Zope tree) to have the default value take effect.
Quite specific to my setup, I'm afraid ...
Can anyone tell me what is the main advantage of using tuple? In what scenarios do I need to use these?
I assume that you're talking about the Tuple<> type and not anonymous tuple classes.
Like an anonymous type, Tuple<> allows you to avoid declaring a new class just to group a few objects. Unlike anonymous types, tuple types have known names and thus can be used as method return and parameter values, etc.
Personally, I try to avoid heavy use of Tuple<> because it can make for difficult to understand code, expecially when used with primitive types (e. g. if you see a Tuple it's not obvious what each field represents).
One place I have found tuples to be very useful is as dictionary keys. Because Tuples implement Equals() and GetHashCode() (not ==, though!), they are perfect for things like private dictionaries that cache information based on a compound key.
It's used mostly to avoid declaring a class / struct with a few properties only for the sake of passing a group of objects around, where only one object can be passed.
Lets say I have a list of urls to go through and if i get an error (4xx or 5xx) I want to build a list and then either later display it to the user or just look at it in my debugger.
I'd catch the web exception and have a Tuple<string, int> (url, http error code) instead of creating a struct for one or two functions to use. Heck it might even be a foreach loop with a breakpoint on if the list has more then 0 items. Thats when it is useful.
I would like to store MetaObjects in a list like this:
myList = QList<QMetaObject>();
myList->append(MyClass::staticMetaObject);
myList->append(MyOtherClass::staticMetaObject);
I want to keep track of these object through out the application but I don't wish to allocate them just yet. By adding some information in my classes I will be able to use the MetaObject function "classInfo(int).value()". I use this when I store them in a QListWidget. When a row in the QListWidget is pressed I would like to be able to create an object of that specific kind that is stored in the list.
(Also have to add that all the classes dervies from the same baseclass)
This sample code describes a bit of what I want to do, except in his example, you add the classes as you go along.
http://lists.qt.nokia.com/pipermail/qt-interest/2012-January/037204.html
I read through the manual and when I try things like:
MyBaseClass *test = qobject_cast<MyBaseClass*>myList->at(i).newInstance();
The project compiles but when I try to print the "test" object its null. What am I doing wrong? And is this the best way of doing this?
Was also looking at MetaType, but where would i be able to store, for example a string for the menus if I'm not allowed to create the object? Would this be a nicer solution if I have a static function that returns a string?
Edit:
I now changed so the constructors are Q_INVOKABLE which solved the problem where "test == null".
But what are the downside of this solution? Should I just use a object factory (the old fashion way with a switch case)?
I found another similar question, but don't quite follow the explanation there, and not sure if it applies the same to me.
I am getting the error:
warning: unable to bind to property 'Description' on class 'Object' (class is not an IEventDispatcher)
this is only when the data is bound to a List as an ArrayList, though. I had it in a Datagrid before (just as an Array) and it did not cause any issue. I'm not expecting to be able to bind any data back to the class 'object' not even sure which object exactly it's referring to.
My list data-provider is an ArrayList.. populated by a result event from an SQL query contained in another class:
private function loadDayComplete():void
{
var Meals:Array = _day.MealResults;
var MealsListResult:ArrayList = new ArrayList(Meals);
MealPanelDataGrid.dataProvider = Meals;
MealListView.dataProvider = MealsListResult;
{
The day class I have is a data holder to get all the data (from several tables) for a 24 hour span.. I have classes for each individual datatype for editing them.
But I'm not sure do I even need to worry about the warning if I don't plan on editing the values? it completely spams the console though whenever I touch anything, so I really would like to get rid of it.
I tried an object proxy as I saw described elsewhere but nothing changed. And I'm pretty confused why it's suddenly an issue on a list component when it wasn't on a datagrid... The text is in label fields right now anyway, which can't even be edited.
The objects causing this warning are probably items inside Meals array.
Make sure that these items are strongly typed (Data Transfer Objects / Value Objects patterns) and that Description field is marked [Bindable].
Depending on the remoting mechanism you are using you may be able to use something like makeObjectsBindable flag which replaces returned Object items with bindable ObjectProxy instances.
But I'll advise strong typing anyway.
You can get rid of it by making your dataProvider an EventDispatcher: ObjectProxy is an EventDispatcher. It will automatically wrap your data to a specified or infinite depth (default behavior).
metaPanelDataGrid.dataProvider = new ObjectProxy(meals);
It's basically the same thing as with ArrayCollection but deeper.
what I meen is to get all objects and their properties, is it possible? How to do such thing?
Read the SharedObject. The documentation is a great start.
Loop through the properties. Depending on how you stored them if they are simple, a for...in loop should do it. If you are storing complex types (like an Object inside and Object, etc.), you need to first check if the object is simple or not. If it is not, you need to loop through its properties.
Luckily, since you've tagged this for flex as well, the ObjectUtils class will be handy for things like checking if an Object isSimple() or inspecting an Object's properties via getClassInfo().
e.g.
//assuming nestedObjectFromSO is a nested object read from a SharedObject
trace(ObjectUtil.getClassInfo(nestedObjectFromSO).properties);
Depending on your structure, you might need to write a recursive function that gets the data from nested objects within your SharedObject.
HTH,
George
You can use AIR Shared Object Editor to grab and edit .sol files.