Tuesday, June 18, 2013

Getting the Qt Creator debugger to work on Windows

Installing the default Qt package for Windows installs the Qt Creator IDE, and everything else you need to write GUI apps, but once you try to debug your first program you get an unexpected surprise.  Unless you have installed the appropriate Windows SDK, the debugger functionality in Creator won't work.  You will get an error message saying the debugger is not configured.

The following is what I had to do to get the debugger to run on Windows 8 x64 with Qt 5:

  1. Download the Windows SDK for Windows 8.  If you have Visual Studio 2012 and selected the appropriate option during that installation, you won't have to run this.
  2. Run the installer for the SDK, and when prompted select the debuggers checkbox.  This is the only thing you really need.  If you want the full SDK select the other checkboxes.
  3. Open the Qt Creator IDE. Go to Tools -> Options -> Build & Run -> Kits.  In the Auto-detected field you should see an entry for your version of Qt.  Selecting it you should see the debugger has been configured for CDB Engine.  If you see < None > for the debugger, you will have to manually navigate to the CDB executable.  The path on my computer is:

        C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x64\cdb.exe

Thursday, June 13, 2013

Adding a custom slot in Qt Designer and Visual Studio 2012

I was going through the "Getting started" section for Qt using VS2012 as my IDE, and I got stuck when I had to add a slot to a button.  Apparently there is a bug when using the Visual Studio add-in, that the submenu Go to slot doesn't show up in a context menu in Qt Designer (see bug).  Needless to say, I spent more than two hours trying to figure out how to get around this problem.  The following is what I found:

Let's say you have a class called Notepad that has a quit button and you want to handle when the button is clicked.  First create a private slot in the class definition in the header file - Notepad.h in this example.

class Notepad : public QMainWindow
{
...

private slots:
    public void on_quitButton_clicked();

...
}

On the Notepad.cpp add the following:

void Notepad::on_quitButton_clicked();
{
}

Note: from what I read it's good idea to follow the convention on_name_signal() for all your custom slots.

Now open your *.ui file with Qt Designer.  At this point I tried using the Signal/Slot editor to add the slot to the button on the GUI.  The "custom" slot we wrote above however doesn't show up when you click the slot dropdown.


After scouring stackoverflow and the Qt forums I found a couple of ways to get the custom slot to show in the dropdown.

  1. Go to Signal/Slots mode by pressing F4 on your keyboard.
  2. Click on the button so that it changes color.
  3. Left-click and drag it to the top of the main window.

    4.  This brings up the Configure Connection window
    5.  On the left pane select the Signal clicked()
    6.  On the right pane select Edit
    7.  This brings yet another window, select the + button.
    8.  Enter the name of the custom slot, on_quitButton_clicked() in this case.
    9.  Click Ok and now you should be able to see the slot in the dropdown in Signal/Slot editor.



Pretty tedious, but if you want to use Visual Studio as the IDE, this is what you will have to go through until someone fixes the bug, or you decide to use Qt Creator.  If I keep finding issues like this by using Visual Studio I think I'll have to do to the latter.

Sunday, June 9, 2013

Goals for the rest of 2013

Since late last year I had some plans about what I wanted to accomplish this year in terms of technical knowledge and programming.  The ideas have been floating in my head, and I have already accomplished several, but I think it will be nice to write them here and see how I much I get done by year's end.

  1. Work with C++ again.  -  C++ was actually my first "real" programming language that I learned to the point I could build some non-trivial applications.  During my time in university, I focused on Java and C, and my C++ knowledge accumulated a fair amount of rust.  This year I plan to get back to working with C++ to the point that it becomes the go-to language when solving computational problems.
  2. Learn Qt.  -  One of the reasons for going back to C++ is that I want to do some GUI applications that can run in both Windows and Linux.
  3. Learn OpenGL.  -  I bought a book about DirectX last year and read a few chapters, but decided that OpenGL would be a better choice since I eventually want to program a game for Android, which only uses OpenGL.
  4. Review algorithms  -  It is my personal belief that I should know everything covered in a standard college algorithms course by heart, and can be able to apply the knowledge at any time.
  5. Code at least one game by December 31, 2013.  -  I've been trying to code a game since I was in high school.  It is the reason I studied Computer Engineering in school.  Too many things have gotten in the way in the past.  It is time.