AUG
25
2005

I hate C APIs

Well, not all of them.
Those that create tons of structs for datatypes and even more functions to work with them.
I hate them because they almost look like sane OOP APIs but are awfully to use compared to
what real OOP languages would offer

Consider this example:

void foo()
{
CFStringRef cfstring =
CFStringCreateWithCString(NULL, "http://wwwkde.org/", kCFStringEncodingUTF8);

CFURLRef cfurl = CFURLCreateWithString(NULL, cfstring, NULL);

// use the URL

free((void*)cfurl);
free((void*)cfstring);
}

Compare that to this:

void foo()
{
QUrl url("http://www.kde.org");

// use the URL
}

The C++ compiler can convert the const char* into an QUrl by going via the QString
constructor without having to be told.

It also takes care about freeing the objects once they are out of scope.
Oh well.

Anyway, in case you are wondering about my above Carbon exercise:
I have been trying to implement the Launcher service for QDS for the Mac OS X platform.

Not having direct access to such a system made that a little awkward, but a friend has been really
helpful and tried to compile anything I sent his way ;)

Unfortunately neither of us was able to figure out why the above code results in weird linker
errors. Googling brought up several other reference for similar problem, seems it is not possible
to mix Carbon and Qt code or, more precisely, ceased to work on more recent OS X versions.

So if you are looking for a challenge and have access to a Mac with Qt3, get qds-0.4.1.tar.bz2
and give it a shot. Your help will be greatly appreciated!

Comments

Change your includes from
#include
to
#include
#include

Also change
free((void*)cfurl);
free((void*)cfstring);
to
CFRelease(cfurl);
CFRelease(cfstring);

The CF apis are always symmetrical, for every Create or Copy you do a Relase.

For more info see http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/index.html and http://developer.apple.com/documentation/CoreFoundation/Reference/CFAPI-date.html#//apple_ref/doc/uid/20001496

Hope this helps
/Tobias

p.s.
The WebKit project (webkit.opendarwin.org) mixes Qt and mac code and also implements many Q-classes (such as QUrl) as wrappers over mac specific code.
d.s.


By tobli at Sat, 08/27/2005 - 12:56

Thank you!

I already discovered the CFRelease thing, not having a Mac myself isn't very helpful when writing Carbon Code :P

The linker problem seems to be an incompatability between Qt3.3.4 and OS X 10.4, I heard it should work with older OS X versions and will work again with newer Qt versions.

Something about symbols changing the library they are in.
Maybe some kind of binary incompatability guideline like "make Carbon ABI change every release so developers are convinces to use Cocoa" :)


By krake at Sat, 08/27/2005 - 18:15