QOF (was QoF)

Neil Williams linux at codehelp.co.uk
Mon May 3 02:44:46 EDT 2004


On Sunday 02 May 2004 10:08, Derek Atkins wrote:
> > I'm trying to understand QOF using the sourceforge example:
> > http://qof.sourceforge.net/my-obj-example.c.html

That's where the GList came from, that QOF example.
It uses the syntax I was trying to understand.
(see later)

> > 	GncInvoice *secondinvoice = gncInvoiceCreate (testbook);
> > 	gncInvoiceSetID(secondinvoice, "2002");
> > 	printf("Invoice ID: %s\n", gncInvoiceGetID(firstinvoice));
>
> So this prints "1001".

Invoice ID: 1001, yes. Simple check line.

> > 	QofCollection *coll = qof_book_get_collection (testbook,
> > GNC_ID_INVOICE); GList *all_my_objs = qof_collection_get_data (coll);
>
> Uh, this function doesn't give you all the list of invoices.  What makes
> you think it would?  

The QOF example on sourceforge. 
/* Print out the baseline: all of the instances in the system */
By passing the GNC_ID_INVOICE I was imitating the MYOBJ_ID in the example. 
Thought it might give me a baseline of all invoice instances in the system. 
Figured it probably wouldn't but it was worth investigating.

What I'd missed was this declaration in the MyObj definition:
   /* Make sure we keep track of every object; 
    * otherwise we won't be able to search over them.  
    * Do this by storing them in a collection.
    */
   QofCollection *coll = qof_book_get_collection (book, MYOBJ_ID);
   GList *all_my_objs = qof_collection_get_data (coll);
   all_my_objs = g_list_prepend (all_my_objs, m);
   qof_collection_set_data (coll, all_my_objs);

That's what makes it a GList and what allows all instances to be retrieved. I 
didn't realise that this was not implemented the same way in gnucash - the 
equivalent coll object is there, but as you say, qof_collection_get_data 
doesn't have to return data suitable for a GList. 

> To find the invoices you either need to iterate 
> (using qof_collection_foreach) to build the list, or you need to
> build and run a Query.

OK. I've misunderstood the QOF example in how it relates to gnucash.

> What makes you think that this should be a GList*?  The API is:
>
>    gpointer qof_collection_get_data (QofCollection *col);
>
> If it returned a GList don't you think it would return a GList?

I know that, I was following the example. The QOF example uses a bespoke 
object, creates some instances, registers the object and then immediately 
goes to this 'print all' loop. Then it creates and runs the query.

   my_app_create_data(book);
   my_app_do_some_queries (book);

That last function executes the print all instances loop and then creates and 
runs the query.

I was trying to do the same thing with GncInvoice - the object definitions are 
in place in the main body of code brought in by the makefile, the 
registration is done in the create and I create a small amount of example 
data.

> In this case you're just being damned lucky.  I have no idea why it's
> working for you at all.  It should just crash.

A crash would have made more sense. 

> The function to get the list of objects.  What you're using is wrong.

> No.  The invoices are all properly registered.  You're just not using
> the right APIs to get at them.

Still learning GTK, Glib and QOF - all at the same time. I'm bound to screw up 
sometimes.
:-)

Incidentally, I moved from using Vi, Kate and gcc directly when I had to keep 
searching for the API. I tried KDevelop but when I asked it to generate a 
project file from the CVS HEAD top directory, it hung and then hung the 
entire system! That's the first time any program has halted this PC.

I'm using Anjuta now - very capable and very helpful with tab auto-complete 
for functions, types, macros, etc.

-- 

Neil Williams
=============
http://www.codehelp.co.uk/
http://www.dclug.org.uk/
http://www.isbn.org.uk/
http://sourceforge.net/projects/isbnsearch/

http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20040503/ebf8cd39/attachment.bin


More information about the gnucash-devel mailing list