From: Unai G. <ug...@us...> - 2003-12-06 23:31:17
|
The funny thing is this. Did you ever notice that my QPtrList classes store _by value_ and not pointer? Yes, read the code. There's no "new"s around. The reason is that the methods in the class create a copy, just to make it easier So yes, I used QPtrlist<type> as QValueList<type> (not type *) without even knowing QValueList existed =) On Tuesday 02 December 2003 16:05, Jason K wrote: > > Using pointers could be faster, but the problem with pointers is > this:> KrecipeDB::foo(QValueList &list)> {> Recipe blah;> > list.append(&blah);> }> "list" contains a pointer to a recipe > that doesn't exist anymore, since the > context changed. Next time the > list is used there will be a nice crash. The same thing goes for a QPtrList > though. That's the joy of working with pointers. The programmer should > know that anything that goes into the list should be allocated with > "new".> The second possible solution and problem is this:> > KrecipeDB::foo(QValueList &list)> {> Recipe *blah=new Recipe;> > list.append(&blah);> }> The problem here is that QValueList > doesn't have setAutoDelete as QPtrList > does, so one must delete th > elements "by hand" later.When we use QValueList<Recipe*>, we'll be > using the RecipeList class. We could easily implement the setAutoDelete > functionality ourselves into this class. Also, the t! he message from Faure > suggested changing QPtrList<Type> to QValueList<Type*>. I > figured this meant there was good reason to use pointers (but i could be > wrong... i'm not exactly in tune with all the internals of these two > classes).> Nice indeed, but I'm not sure how to deal with that. The > whole code to resize > the recipe into screen deals with a single > recipe, and I don't think that > code will work nicely if you have a > page of 30 recipes long. The code to export multiple recipes onto a single > HTML page has already been done (finished less than a week ago). You can > see for yourself by exporting a category as HTML. -Jason > > _______________________________________________ > Join Excite! - http://www.excite.com > The most personalized portal on the Web! |