[Kde-pim] Accessing the addressbook from C++

Christoph Kies mail at ckies.de
Thu Jul 31 10:10:08 BST 2008


Hello everybody,

This is my first posting in an kde list.

As mentioned in the subject, I want to Access the addressbook from C++.
I am using Debian Lenny/Testing with KDE 3.5.9

I am C++ programmer with some QT3 experience but i have no clue about kde 
programing.

As a starting point, i found this:

  KABC::AddressBook *ab = KABC::StdAddressBook::self();

  AddressBook::Ticket *ticket = ab->requestSaveTicket();

  if ( ticket ) {
    KABC::AddressBook::Iterator it;
    for ( it = ab->begin(); it != ab->end(); ++it ) {
      kdDebug() << "UID=" << (*it).uid() << endl;

      // do some other stuff
    }

    KABC::StdAddressBook::save( ticket );
  }

I found it here: 
http://api.kde.org/3.5-api/kdelibs-apidocs/kabc/html/classKABC_1_1StdAddressBook.html

But it did not compile, requestSaveTicket() does not return an 
AddressBook::Ticket but an KABC::Ticket so i changed this.
But KABC::StdAddressBook::save(ticket) does not exist.
there was only an KABC::StdAddressBook::save() without an argument, and that 
in turn was depreciated.

Finally i wrapt all in the simplest possible program:

#include<kabc/addressbook.h>
#include<kabc/stdaddressbook.h>

int main(int argc, char *argv[])
{
	KABC::AddressBook *ab = KABC::StdAddressBook::self();
	
	KABC::Ticket *ticket = ab->requestSaveTicket();
	
	if ( ticket ) {
		KABC::AddressBook::Iterator it;
		for ( it = ab->begin(); it != ab->end(); ++it ) {
			kdDebug() << "UID=" << (*it).uid() << endl;
			
			// do some other stuff
		}
		
		//KABC::StdAddressBook::save( ticket );
	}
}

And compiled it with:

g++  -I/usr/include/kde  -I/usr/include/qt3 -L/usr/lib/kde -L/usr/lib/qt3/lib -lkdecore -lkdepim -lqt-mt -o 
kabctest kabctest.cpp

It compiles but it does not run, i get an  "Speicherzugriffsfehler" which 
means "segmentation fault".

what can i do now? Compile with symbols and run the gdb?

thank you
Christoph
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list