Developing with Qt Creator

I recently decided to switch to develop in Linux, and switch from MS Visual Studio to Qt’s official cross-platform IDE: Qt Creator. I have to say it is quite a responsibility to replace Visual Studio, because from my personal experience Visual Studio is one of the best IDE’s (and also the best Windows application).

First things: to migrate a QT based project from Visual Studio to Qt Creator is not really an headache. First of all, generate the project file (.pro) in Visual Studio (if you don’t have it already), and be sure to “tune” it as you like! Next thing, you can import into QT Creator as a project file, and everything should run out-of-the-box.

One thing that deserves attention are the building configurations. You need to add at least one building configuration, for the Qt Version in use. You can do that by going to “Projects” on the left side pane. By default, Qt will create a “debug” and a “release” mode, so you will only need to setup one configuration. “Shadow builds”, are builds located outside the source directory, which as a matter of principle is a “tidy” idea; to enable them, you just have to check the “shadow build” checkbox, under each mode. Regarding the run configuration, I would think that is a good idea to point to the debug binary, if you ever want to debug your application (I bet you will). And this brings me the last topic: debugging in Qt Creator.

The fact that there is not so much documentation about Qt Creator (apart from the fancy “welcome wizards”) and the lack of profile and analysis tools, when compared to MS Visual C++ does not bother me too much. But what really bothered me was to be able to setup the debug, and since I almost spend a morning on that, I will write it here and hope it will be useful to someone.

In a nutshell, Qt Creator uses the Linux “official” compiler g++, and official debugger,gdb. As a general concept I think that is great: why develop new tools, when you have working (great) ones?
Now to have the gdb working correctly with Qt Creator is another story. I installed the latest version, from the ubuntu repositories:

sudo apt-get install gdb

It did not really worked very well. Then I read that Qt Creator uses python for debugging and that gdb had to be compiled with Python enabled, so I found a version of gdb released by the Qt Creator project, and switched to that one. It did not work very well either. Finally, after many combinations, I discovered that it was actually Python that had to be “gdb-enabled”. So I installed this version of Python:

sudo apt-get install python2.7-dbg

And “asked” my system to use that one as a default:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7-dbg 30
sudo update-alternatives --config python

(the exact code differ for your system).
Finally, I tested the python support in gdb by calling it from the command line and entering a python command.

GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
.
(gdb) python print 123
123
(gdb)

If you see the “123” on the gdb prompt, everything should be ok. Finally I tested gdb with my application, running it from the command line:

gdb faocasd

If all is running ok, then you can go back to Qt Creator and start the application in debug mode (by pressing F5). I encountered a few other small problems, but I was able to debug. Important to mention that the debugger does not always pick the changes, for which I advise you to always recompile your project! (I know, it may be annoying for a large project).

All is well, when it finishes well: here is my “hello world” Qt Creator debug! 🙂

Hello Debug! :-)

Advertisements

One thought on “Developing with Qt Creator

  1. Pingback: “Hello World” Cross-Compiling | heartcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s