QOF (was QoF)

Derek Atkins warlord at MIT.EDU
Sun May 2 17:08:11 EDT 2004

First, it's QOF, not QoF.  QOF == Query Object Framework.

Neil Williams <linux at codehelp.co.uk> writes:

> I'm trying to understand QoF using the sourceforge example:
> http://qof.sourceforge.net/my-obj-example.c.html
> This is part of a file (I have a header and a genuine makefile to compile) but 
> I keep getting an empty GList returned at this line:
> 		printf("Debug: %s\n","zero length objects");
> 	GncInvoice *firstinvoice = gncInvoiceCreate (testbook);
> 	gncInvoiceSetID(firstinvoice, "1001");
> 	gncInvoiceSetActive(firstinvoice, TRUE);

You don't need to do this.  Invoices are Active by default.

> 	GncInvoice *secondinvoice = gncInvoiceCreate (testbook);
> 	gncInvoiceSetID(secondinvoice, "2002");
> 	gncInvoiceSetActive(secondinvoice, TRUE);
> 	printf("Invoice ID: %s\n", gncInvoiceGetID(firstinvoice));

So this prints "1001".

> 	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?  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.

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?

> 	if(g_list_length(all_my_objs) == 0) {
> 		printf("Debug: %s\n","zero length objects");
> 		all_my_objs = g_list_prepend(all_my_objs, secondinvoice);
> 	}
> 	for (n=all_my_objs; n; n=n->next) {
> 		GncInvoice *m = n->data;
> 		printf ("id=%s\n", gncInvoiceGetID(m));
> 	}
> }
> The forced addition of secondinvoice renders the expected id=2002\n output but 

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.

> I should be getting both 1001 and 2002, shouldn't I?

No.  See above.

> What am I missing?

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

> Do I need more objects in testbook before the invoices are properly registered 
> or do the invoices need more data before the qof hashtable lookup can work?

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


       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available

More information about the gnucash-devel mailing list