[Interest] Best practices for making a Qt facade for a C library
Dmitriy Purgin
dpurgin at gmail.com
Wed Jan 14 12:10:15 CET 2015
Hello Ian,
thanks for your reply. I think I can use some ideas from QtGstreamer,
didn't really know about its existence. I'll try your approach, it feels to
me so much better, but I'd prefer composition over inheritance.
Thanks!
Cheers
Dmitriy
2015-01-14 5:26 GMT+06:00 Ian Monroe <ian at monroe.nu>:
> On Tue, Jan 13, 2015 at 10:57 AM, Dmitriy Purgin <dpurgin at gmail.com>
> wrote:
>
>> Hello all,
>>
>> I'm developing a small Qt project for SailfishOS (a Linux distribution,
>> Meego descendant, Qt 5 based) and had to use some of PulseAudio (a sound
>> server for POSIX OSes) API functions which are pure C. I've wrapped them in
>> a couple of classes but it's evolving to something bigger now and I'm
>> trying to detach these into a shared library which seems to become a basic
>> PulseAudio binding. It's my first facading of a C library and I'm kind of
>> stuck on the architecture now and hope that someone can share ideas on
>> that.
>>
>
> Have you looked at the code generation done by QtGstreamer for glib stuff?
> Not sure if it's any good, just want to make sure you know of it:
> http://cgit.freedesktop.org/gstreamer/qt-gstreamer/tree/
>
>
>> So with the problem stated, my question is: does anyone know any "good
>> practices" in designing this kind of relationships between classes or can
>> share similar designs to look at? There's no technical problem for me to
>> expose the inner parts of some classes to some other classes, I just
>> wondered if there's a subtle way of doing this.
>>
>
> I wrap a C library and had a similar situation. My solution in this case
> would be to give QtPulseAudioSource a new base class named something like
> PulseAudioInterface. That class defines pa_context, it could possibly just
> be a void pointer. It has a member variable for it and a
> setPulseAudioContext method. Then QtPulseAudioContext would have a class
> called something likeblessPulseAudioInterface. QtPulseAudioSource could
> call it in its constructor.
>
> In this way it is pretty hidden from users of the library, and
> QtPulseAudioContext has zero deps on AudioSource.
>
> Ian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150114/6652cedf/attachment.html>
More information about the Interest
mailing list