Archive for the ‘Qt’ Category

Qt5 Pretty Printers for GDB

4th June 2014

If you’ve ever debugged a Qt program in GDB and been frustrated when attempting to print a QString gives you an unhelpful result like

$1 = {d = 0x6e7c40}

then kde-dev-scripts has some useful tools for you. For some time now, there has been the kde-devel-gdb script, which you can include in your ~/.gdbinit. This gives you commands like “printq4string” and “printq5string” which will dump the actual string contents of a QString.

However, GDB 7 has the ability to add pretty-printers written in Python. This means that you can control how a value is output when you use “print” and when backtraces are printed. So “print someQString” will actually write out the string for you.

The gdb directory of kde-dev-scripts now has some of these pretty-printers for Qt5. Currently, it covers most of the main value classes and collection classes in QtCore (QByteArray, QString, QStringList, QList, QMap, etc). QHash and QSet are the most notable ones that are missing.

To use these pretty-printers, you either need to source the “” file in your GDB session, or use the “” script to generate files that will allow GDB to auto-load the printers when it loads the Qt5 libraries.

I plan to eventually submit these to Qt, so that pretty-printing of Qt value classes will work out of the box. For now, do let me know if you run into any issues with them (don’t forget to compile your application with debugging symbols!), and feel free to extend what’s there, or use it as a template for some Qt4 pretty-printers.


D-Bus threading issues

1st June 2010

There are some annoying issues and crashes in KDE 4 (and particularly in KRunner and Nepomuk) that are related to the thread-safety (or, rather, thread-non-safety) of libdbus-1.  kde-core-devel has seen some discussion about this recently.

There is a patch that fixes the issue, but it won’t make it into D-Bus before dbus-1.4, due to the fact that it changes the library behaviour and could potentially break bindings.  Thiago has confirmed that the change doesn’t break the Qt bindings, and (from the bug report), no-one has found any other bindings it breaks.

This is all just background on why, if you are running Arch Linux, you might want to check out the dbus-core-mt package on the AUR.  It’s dbus-core-1.2.24, as found in core, but with the afformentioned patch applied.  Note, however, that you use it at your own risk – it should improve KDE, but it may well break other stuff.

Think Better

17th December 2008

I suspect many of you will remember Apple’s adverts a few years back, with the tagline Think Different.

Think Different

Think Different

Not think better.  Not think world-changing.  Think different.

What does “different” mean from the point of view of a user or developer?  Different file formats.  Different systems.  Things that don’t interact.  A hundred different bugs in every application.  Just ask a web developer what they think about different browser implementations.

Developers get faced with choices between different systems all the time.  Why should I use system A instead of system B?  Does system A do something that system B doesn’t do, and do I care about that something?  If so, then this is an excellent reason to use system A.  Perhaps system A does the same thing as system B in every regard that matters to me, but does it better.  This is still a good reason to use system A, providing I haven’t already invested heavily in system B.

But “different” isn’t better automatically.  From the point of view of a commercial entity, “different” is generally worse by default.  “Different” costs money.  Is it worth it?  You have to justify that, justify why different is better in this case.

In light of this, I have a question for you, the contributing community of KDE.  What makes KDE better?  What makes it world-changing?

Doing something revolutionary

Let’s make this a bit more specific.  Most immediately I’m interested in what KDE has to offer the software industry at large.  What is KDE pioneering that would make a company that has historically based it’s business model on web applications built on Microsoft technology, but is now branching into open source because it’s not afraid to follow interesting trends, sit up and pay attention?  Consider a target audience of someone who thinks the time of the WIMP interface is over, but that the iPhone is a testament to the ingenuity of graphical designers and not software engineers (and software engineering is what we’re interested in here).  Consider the trend towards service-based computing.  Consider Google’s dominance.

Think about seamless integration of mobile devices, of reading something at your computer, then having to rush off and getting it onto your iPhone/eeePC/PDA/portable toaster with almost no interaction required.  Think of the problem of sifting through the cruft of the intarwebs (cat captions and all) to find that useful nugget of information.  Think of how your life revolves around trust networks (who do you ask for advice?), but how poor computers are at duplicating that.  In short, think of the unsolved problems in computing.

Is the semantic desktop (cf Nepomuk) a bold leap into the future of computing?  If so, how?

Is JOLIE integration into the desktop layer where it’s at?  Why?

Will Plasma revolutionise the way we interact with small form-factor devices?

What problems are KDE solving that haven’t been solved before?

Remember, we’re thinking here about why people who’ve never heard of KDE and see Linux as a server OS should be interested in what we’re doing.  We’re thinking about why budding young developers who don’t care about the GNU software libre philosophy but just want to work on an exciting, intellectually challenging and world-changing project might jump at the chance to get involved with KDE.

Doing something better

Secondly, why should people (again, who don’t care about the KDE desktop) use our development framework?  What makes us better?

Perhaps Eigen is the matrix library to end all matrix libraries?

What can Akonadi offer the world beyond the kdepim module?

How will Plasma make the hoards adore your application?

In what way are KComponents the light side to COM and CORBA’s dark side?

Why should you embed Marble into your application?

How is KDE solving the problems that developers care about in a better way than they have been solved before?

Final words

I’m fully convinced that KDE is awesome.  I care about software freedoms, and KDE is free.  I care about frameworks and APIs, and Qt/KDE beats the competition easily in that regard.  But I want to be able to evangelise KDE to other developers who don’t care about these things, and I don’t have the knowledge to do so.

Post your responses in the comments, or put them straight down on my Techbase page.  I will try to collate everything there.

Open Hardware

1st November 2008

Being a hacker, the part of free and open-source software that really appeals to me is being able to tinker.  This is why I use Arch Linux rather than its more polished compatriots.  But I’m also interested in the way volunteer communities largely composed of hoobyists and enthusiasts can be leveraged to solve problems that are normally very expensive.

Even after only working in the software industry for a couple of months, I can already see how writing software is an expensive business for companies like Microsoft.  Developers’ time is not cheap, and it takes a lot of time to produce a product of any complexity.

But you only have to look at Linux or KDE or GNU to see the levels of complexity that can be reached by people working essentially for free.  Sure, there are people being paid to work on all of those areas, but even then the fruits of their labour are being given away for free.  They can’t even do what Qt Software does and simultaneously sell a commercial version and give away a free one, because they don’t own the copyright to the whole codebase and hence can’t dual-license it.

All this is why I was interested to read about how the ideas of open source are being applied to hardware.  It’s a fascinating read for anyone interested in the mechanics and economies of open source.

Another Day, Another Release

12th August 2008

Yes, releasing MPRIS Tester 1.3 a day after 1.2 is a bit ridiculous, but Fred Emmott pointed out a serious flaw for a D-Bus interface tester program: the type for the MPRIS Version field was wrong.  It should have been a struct of two uint16s, but instead I had it as two ints.

For safety, I’ve also specified that the status field is comprised of 4 int32s, rather than simply ints.  I hear tell of one (C, admittedly) compiler that implements ints as 24 bits…

MPRIS Tester 1.2

11th August 2008

MPRIS Tester 1.2 is now available at

Changes since 1.1: Clear Console now works, and the log of received signals now shows the argument to the signal (well, except for trackChanged() where I didn’t want to flood the log with all the metadata of the new track).

You can find out more about MPRIS Tester from an older post.

MPRIS Tester 1.1

6th August 2008

Briefly: I’ve updated the MPRIS Tester to version 1.1.  This update just improves a couple of bits of the user interface (not that any of it is amazing) – the log now has timestamps, and the capabilites are displayed as labels rather than greyed-out checkboxes.

Confused?  Read my introductory post about MPRIS Tester.

MPRIS Tester 1.0

20th July 2008

I’ve just ironed out the last few creases (that I’ve found so far) in my MPRIS tester. It should now thoroughly test all parts of the MPRIS spec. Well, none of this testing is automated, but there’s only so much automated tests will do for you with something like this.

I’ve already used it to find a problem in Amarok’s handling of structs of ints (the same problem the first version of the MPRIS tester had).  I found some handy documentation about how to do just that.  It shows up a few more bugs in Amarok’s MPRIS interface that I’ll attack at some point if peterzl doesn’t get there first.

Note that this can be used as a rather rough-and-ready controller for any MPRIS-capable players on the local system, but it isn’t geared towards that and isn’t pretty.  It deliberately exposes all the internals of the MPRIS interface.

You can grab the code (only a 10K download!) at, and here’s a screenshot of the final beast in action:

MPRIS Tester 1.0

MPRIS Tester 1.0

MPRIS Tester

20th July 2008

I’ve just finished writing a tester app for MPRIS.  It covers all the parts of the standard for querying and controlling media players over D-Bus.

It’s pure Qt, since I didn’t need any KDE-specific stuff – it’s just a quick hack, anyway.

I was going to write it in (and use it to learn) a scripted language like python, but I got impatient.  I might reimplement it in an interpreted language at some point.

There are a couple of problems (to do with receiving structs of ints) that I need to track down to either my program or Amarok (or both – I reference Amarok’s code when implementing those bits).  But other than getting the status and the MPRIS version, it seems to work.  And I think it’ll be a handy little tool.

I’ll upload it to when that site returns to normality, but in the meantime:

MPRIS Tester

MPRIS Tester

Edit: The application can be found at Qt-Apps.

Printing QStrings in gdb

12th May 2008

I’m still learning the power of gdb. It’s an immensely useful tool for debugging programs (funny, that…).

Today I wanted to find out the contents of a QString. “print s”, where “s” is a QString, doesn’t do much for you, though. The data is stored as an array of ushorts inside a shared data member. But all I want is to print out the string as it would appear if I did “qDebug() << s”, for example.

Solution: head over to the kdesdk module, and into the scripts directory, where mountains of useful bits reside. The script you want is kde-devel-gdb.

Now copy this to your home directory and put the line “source ~/kde-devel-gdb” into your ~/.gdbinit file. Or, if you’re building KDE in the manner prescribed on techbase, you can just put “source /home/kde-devel/src/KDE/kdesdk/scripts/kde-devel-gdb” into your ~/.gdbinit file.

To use, check out “help user-defined”.  For example, to print a QString called s, type “printq4string s”.  Ta-da!