>It has been quite some time since I last blogged. Lots of things are going on, so the time to sit down and reflect has been… let’s say limited.
Author: Johan Thelin
Qt as GTK, again
Another set of night hours spent hacking on making the GTK API wrap Qt. I focused on adding functionality and not on cleaning up, so no code this time either. I just want to show the progress.
- Replaced the gtk/gtk.h headerfile with my substitute.

The next example, table packing, simply demonstrates the grid layout abilities of GTK. There seems to be a couple of pixels between the rows for some reason (I will investigate at a later point), but apart from that, everything works. The changes made are the same as for the first example.
- Replaced the gtk/gtk.h header with my substitute.

Robin Burchell (w00t) has attempted something similar in the gqt project (gitorious link). We will discuss how we can join forces ASAP (I’ve been sort of unavailable this weekend). The gqt project has clean code – look great. It employs a different approach than I when it comes to mapping signals/slots/events and for handling the construction of menus.
- Replaces the gtk/gtk.h header file with my substitute.
- The popup is always shown at (100, 100) as the GdkEvent structure cannot be cast to a GdkEventButton structure.
void gtk_container_set_border_width(QObject *o_w, int spacing) { QT_WIDGET_ASSERT(w)w->setContentsMargins(spacing,spacing,spacing,spacing); }
>GTK+ made Qt
>Disclaimer! First of all – this is not an attack on any toolkit, nor critique. Rather, it is a hacker sitting down and trying out an idea.
- Event handling functions get NULL instead of a GdkEvent pointer.
- Packing flags (e.g. homogenus and spacing when calling gtk_hbox_new) ignored – I simply use QVBoxLayout, QHBoxLayout and QGridLayout where they fit best.
- Only a minimalist part of the API has been implemented (the process is build, add missing symbols, repeat)
- Most GtkXxx classes are defined to a QWidget. Objects are casted up and down all over the place to work around this.
However, the problem isn’t really matching the APIs to each other and getting every pixel right. At least, that is not the current problem. Instead, matching Qt’s C++ style OO to GTK+’s is the problem. What are the differences? I hear you ask.
#define G_OBJECT(obj) ((QObject*)(obj))
#define G_CALLBACK(func) ((void*)(func))
typedef void* gpointer;
typedef bool gboolean;
typedef char gchar;
#define g_print qDebug
...
#define GtkWidget QWidget
void gtk_widget_show(QWidget *w) { w->show(); }
#define GTK_WINDOW_TOPLEVEL (0)
QWidget *gtk_window_new(int) { return new QWidget(); }
void gtk_window_set_title(GtkWindow *w, const char *t) { w->setWindowTitle(QString(t)); }
...
#define GTK_BOX(obj) (obj->layout())
void gtk_box_pack_start(QLayout *l, QWidget *w, bool expand, bool fill, int padding) { l->addWidget(w); }
void g_signal_connect(QObject *src, const char *cstrEventName, void *f, void *data)
{
QString eventName = QString(cstrEventName);
if (eventName.endsWith("_event"))
{ // This is an event, f is an eventFuncPtr
QObject *o = QGtkEventFilter::createFilter(eventName, eventFuncPtr(f), data);
if(o)
src->installEventFilter(o);
else
qWarning("Failed to match GTK event '%s' to a Qt event filter.", cstrEventName);
}
else
{ // This is a callback, f is an callbackFuncPtr
QObject *o = new QGtkCallbackBridge(src, callbackFuncPtr(f), data);
const char *signalName = 0;
if(eventName == "clicked")
signalName = SIGNAL(clicked());
if (signalName)
QObject::connect(src, signalName, o, SLOT(trigger()));
else
qWarning("Failed to match GTK signal '%s' to a Qt signal.", cstrEventName);
}
}
>The wether forcast mentioned snow on Wednesday. We had some yesterday and today it is really snowing away. Looks like I’ll have to buy a sledge for Lisa! Will be great fun.
>TV Star
>Alessandro is the TV star of Qt. Great stuff here.
>One month of flying
>It has been a month since I started working in my own business. My former employer has been very kind and let me explore this while on a leave of absense, i.e. I have somewhere to return to.
- Bookkeeping – there are a lot of receipts to handle, especially when starting. Insurances, web servers, car insurance, etc.
- Working from home – it works fairly well for me. I’ve come up with a scheme to keep myself motivated and actually working. However, a simple business lunch now takes three hours instead of one.
- Money takes time – I’ve been given offers, signing deals, working more than ever, and my next pay check is still not due until mid January. Worth thinking about.
- Time is not money – at least not yet. By being self employed I’m so much more flexible so that I get more quality time with my family, while making the money that I need (and some extra, but I guess that is for future expenses).
So, one month done, many more to come. This far, I’m looking forward to work every day.
>FSCONS 2009
>So, it is kind of stupid to write about these things afterwards, but the time before a conference is always filled with preparations and far too much time spent in OO.o Impress.
>Warning – broken links ahead
>So, the day finally came when I switched from a fairly broken and badly styled MediaWiki-based web page to a WordPress-based one instead. This not only means better management abilites, a working search engine, a proper editor, etc. It also means that links are broken. I don’t write are likely to be – there are broken links out there as I have not migrated all contents. If you run into one – feel free to tell me and I’ll try to sort it out.
The result from this move will hopefully be a more professional presence on the web for my part. Unfortunately I do not have the time I want to polish the site – now I have to prepare my workshops (1, 2) for FSCONS. These events always seems to be so far away into the distant future when I sign up for them – and now it is only two weeks left…
>Off to DevDays
>I’m packing and trying not to forget anything, because my brain will be in auto-pilot-mode tomorrow at 4:50 when the taxi comes around to start my journey to DevDays’09 in Munich.
>KDE 4
>I’ve finally made the switch on one of my working, production mode, computers. The switch from KDE 3.x to 4.2.2 (I think – whatever Kubuntu comes with). I must admit having been sceptical to all the hype about plasma here, plasma there. Social desktop? I want my old workstation look and feel – I thought.
I absolutely love KDE 4. There is so much new, but everything that is different feels intuit. My very favorite feature is, this far, the device notifying plasmoid. Not having to show the desktop to mount, open or unmount my USB-stick is just – smart and intuit.
Now all I have to do is to find out how to change the clock to a 24h mode… (just noticed, taking the screenshot, after using the desktop for a week…)