Recent blog entries for e8johan

Package names

Dear lazy web,


I'm working on a presentation on getting started with Qt. For it, I need package names for Qt for different distros. E.g. (k)ubuntu: qt-sdk, debian: qtcreator. What package installs QtCreator + Qt and needed tools for your distro? Please comment!

Thank you!

Syndicated 2010-04-09 10:47:00 from Life of a Developer

Overload

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.


The last week, I sadly missed foss-sthlm, due to snow. Apparently Swedish trains are built for the summer, so I hope that there will be another get-together later this spring.

I've also been working hard on my embedded Linux course. The course date is kind of tight on the Easter, but hopefully STF can find a nice crowd to work with.

Finally, I've been spending time trying to learn QtQuick (QML, Declarative UI). I'm really enjoying Jürgen's blog on this, as the approach feels new to me.

Syndicated 2010-03-01 15:21:00 from Life of a Developer

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.

Wrapping Qt in GTK might seem like an impossible task, but the fact is that both toolkits, in turn, wrap the same APIs themselves. So, how does the progress look this far?

Upgraded Hello World (link)

The first example, upgraded hello world, works like a charm and does what is expected. There is only one change that has to be made to the example, and the need for it will go away when I've started cleaning the code.

Changes made to the example:
  • Replaced the gtk/gtk.h headerfile with my substitute.
Table Packing Example (link)

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.

Changes made to the example:
  • Replaced the gtk/gtk.h header with my substitute.
Manual Menu Example (link)

Robin Burchell (w00t) has attempted something similar in the gqt project (gitorius 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.

Robin mentioned that one of the major hurdles when mapping the APIs is that GTK uses a widget based structure for menus, while Qt uses QActions for menu items. To have a swing at this, I decided to attack the manual menu example next. It took some changes to the main approach of the wrapping effort, but now I think I have it sorted out.

Changes made to the example:
  • 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.
Manual Menu Example

Another benefit of doing the manual menu example was that I had to have a better look at the events mechanism. As it seems, the "event" signal hooks into all events (like a Qt event filter). This means that there has to be a general event filter, as well as specific event filters (for when connecting to a specific event such as "delete_event"). This kind of breaks my idea of splitting out the code for creating a specific GdkEvent for each type of event in a separate class, so I need to think a bit about that (shouldn't really be a major issue - I just don't want code duplication).

Back to the menu widget versus action approach. As it seems, the QAction and QWidget classes' common base is the QObject class. Thus all pointers to GtkWidget, GtkWindow, etc. needs to be pointers to QObject. That way, the menu object can be made to match quite nicely. The downside is that the code already contained quite a lot of casts. Now it has even more. For instance, a trivial function such as gtk_container_set_border_width needs casting:

void gtk_container_set_border_width(QObject *o_w, int spacing)
{
QT_WIDGET_ASSERT(w)
w->setContentsMargins(spacing,spacing,spacing,spacing);
}

The QT_WIDGET_ASSERT macro creates a QWidget pointer named w, by casting o_w using qobject_cast and then asserts that the pointer isn't null. I'm not sure of the performance penalty of this, but I guess there is one. However, to compensate, all of GTK's GTK_WINDOW, GTK_BOX, etc. are instead defined as simple pass-through macros. This means that performance wise it is a race between GTK_CHECK_CAST and qobject_cast.

I did consider putting the qobject_cast calls in the GTK_xxx macros, but that would not work. For instance, gtk_menu_shell_append can place a QAction in either a QMenu, or in a QMenuBar. As the function is given a QObject pointer, it can now determine (by casting) if the container is a QMenu or QMenuBar and act accordingly.

So, where to next? I belive in fixing the known bugs before continuing. Especially when working on a project such as this, which I suspect will backfire anytime soon (it has been too easy this far). This means that the next step is to do something about the GdkEvent structures to get the popup of the manual menu example to work properly (now it appears at a static location). After that? Cleaning and merging with gqt...

Syndicated 2010-01-18 08:19:00 from Life of a Developer

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.

It has been a couple of years since I first tried out this idea (some seven, I believe). This time, licensing permits it and I believe that the timing is right. So, without further ado, let me introduce GTK+ made Qt.

Qt and GTK+, and all other toolkits out there, provide more or less the same functionality (take that with a grain of salt, but the core is true). So, my idea was to wrap Qt in a GTK+ API layer. Just to see if it could be done. Attacking the problem at this level might be considered stupid - but I like to get results fairly quickly, and this way I can work with GTK+ code directly, instead of writing a ton of underlaying code just to get something to compile.

There are tons and tons of corner cases and not so corner-ish cases that can make this break. The implementation is miles and miles from perfect and the code I've been testing it on is rather trivial. What I've done is that I've taken one of the examples of the GTK+ 2.0 Tutorial and made it do what it is supposed to do (sort of). Examples of what I've ignored in the process:
  • 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.

To create a trivial dialog in Qt, you inherit the QDialog class and then create the children in the constructor of your new class. In GTK+, you generally create a function for creating the dialog in question. In that function, all widgets (including the dialog) are created and put in a proper hierarchy. The resulting hierarchy of widgets is (95%) identical, and all the custom code to make it tick is there - it is just placed differently in the source.

Another difference that has a large impact is the fact that Qt event handles are virtual methods of QObjects and slots are QObject methods. In GTK+, they are plain C functions that are passed as function pointer to g_signal_connect calls.

So, the starting point is this example. I've placed that code in helloworld.cpp (we need it to build as a C++ source file, I'm sure that GCC can be convinced of that by other means, e.g. by using g++ directly, but just changing the extension does it for me).

The only change made to the source code itself is that the include of gtk/gtk.h has been replaced by the inclusion of gtk-made-qt.h (no, the name is not critique, it is just my strange humor). The header file is the container of the rest of this experiment.

The GTK+ Hello World example running in QtCreator on Windows Vista

First of all, I've made some rather rude typedefs and defines with regard to GLib (this just shows how much that needs to be redone to do this properly):

#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

...

There is more of this of course, and some of it is spread out across multiple header files. Next follows the same horrific crime, but this time made to some of the GTK+ widgets:

#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); }

As you can see, straight forward, brute force, get the job done hacks. All this shows how close the different APIs match. This is trivial code (albeit unsafe) and adds almost no extra conversions or checks.

The really interesting part is the implementation of the g_signal_connect function. Here, bridges for both events and signals/slots are dynamically setup. So, here it is in all its glory:


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);
}
}

To my surprise, that is all that it takes. The QGtkCallbackBridge is a trivial QObject that calls the given function pointer with the QObject::sender() and the given data pointer when signalled. The QGtkEventFilter is not much more complicated. It simply filters out the event in question and triggers the given function pointer in much the same way. I've created a factory for the event filters, as I want them to re-create something looking like the original GdkEvent structure. There is actually one event filter class for each type of event, just so that this code can be added.

Well, I've not packaged the code yet. My goal is to try at least one more example first (perhaps two, given time). In the mean time, let's see if this can be made useful (a large enough portion of the GTK+ API needs to be implemented for that) - and if the idea is interesting at all (from a political standpoint, etc). As it stands now, this might help porting GTK+ applications to Qt only platforms, or it could be used as a migration kit (not that I encourage people to migrate from GTK+ to Qt - it is a choice that every developer has to make - use whatever feels comfortable to you).

Syndicated 2010-01-15 15:47:00 from Life of a Developer

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.

Right now I'm sitting, writing about Qt's new animation classes released in 4.6. Looking at the snow, writing about this, makes me wonder if it wouldn't be a good idea to implement animations that delete themselves and their items when the item leaves a given bounding rectangle.

Why? Then you can define a bounding rectangle, e.g. the screen, and create snow flakes with randomized animations and just let them drop.

I remember doing something like that back in the STOS/AMOS days. You created a sprite, defined an animation pattern and then forgot about it (as I recall). This was great for the 2D shooters of the time with aliens attacking in predefined patterns. Not 100% sure how the surviving aliens (yes, you have to take bad players into account, including me) where handled. The ones you hit could be taken care of in a collision detection handing function called from the inner loop... well, nostalgia might make me look at this in a forgiving light.

Anyway, the snow is falling. There will be more tomorrow. It will probably be cold all the way to Christmas. Looks like we're in for a white Christmas.

Syndicated 2009-12-15 09:27:00 from Life of a Developer

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.


This Monday I sent my first large invoice to my biggest customer. Now, time to wait for the next pay. What have I learned this far?
  • 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.

Syndicated 2009-12-02 11:52:00 from Life of a Developer

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.


The last Saturday I attended FSCONS'09. This turned out to be another great event (I've been there two years now). I met lots of interesting people and got faces to a couple of names who's blogs I've been following for a while now.

My plan for this year was to do two workshops - one on Qt for Embedded Linux (which I try to focus on), and one on the Qt SDK, trying to get people started. Both these sessions turned into something else - probably due to the unclearness of what a workshop is intended to be.

The Embedding Qt workshop (slides) had a great turn-up. The idea was to go through the configuration process of Qt/X11, Qt/embedded targetted at QVFb and then have a look at the configuration and deployment of Qt for an actual embedded target. Given a 90 minutes slot, I knew that compilation time was going to be an issue. When it turned out that only one attendee wanted to give it a try, this session turned into an ordinary talk (the one brave guy gave up after the Qt/X11 build - thank you still!). However, the talk was great, lots of interesting questions and great feedback. I really enjoyed the interaction with the audience and at the end Knut Yrvin (an actual norwegian troll) showed up, adding even more facts to the discussion.

The Qt SDK workshop (too few slides to share) also had a great turn-up. My plan was to get people to install the SDK and then show them the basics. I think that something like 5-10 people actually ran the installer, so that was a great success. The demo, however, could have needed some more planning from my side. I showed signals/slots, some widgets and the concept of layouts. For that, I used 40 minutes of my 30 minutes slot, so there where loads of unaswered questions at the end (thanks for everybody coming up to me afterwards having a chat).

To summarize - my aim with workshops did not really work in this setting, however, the quality of the audience and the resulting discussions turned this into a great event for me. I hope that you liked it as well!

Syndicated 2009-11-15 14:27:00 from Life of a Developer

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

Syndicated 2009-11-01 13:29:00 from Life of a Developer

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.


I'm really looking forward to this, and this year, I'll even get to speak a few words in the Qt in Education track on Monday. But the biggest upside is to meet all the people in real life. I'm especially looking forward to meeting the QtCentre crew - and all the trolls of course.

Syndicated 2009-10-11 07:26:00 from Life of a Developer

355 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!