Category Archives: programmer

MFC to Qt migration part 1

Last Monday, after spending weekend planning the development for my upcoming software, I realize something important. One big challenge in developing the software is GUI, and MFC, being my main GUI framework since my first application is not really developer friendly, and totally a nightmare (just like any other Microsoft developer’s tools, really). And after one month playing with Qt, I realize how easy to develop a GUI with it.

For those who still confused about what I do exactly, this is a screenshot of my MFC based application. It’s an application that can read handwritten character using ICR (Intelligent Character Recognition) engine.

icr reader

ICR-based document reader

I decided to give Qt a go. And after spending one day, creating the base UI , I started to integrate my previous project which mostly, developed using Visual Studio 200 and some of it using linked to MFC runtime. At this stage, I don’t want to rewrite all my libraries in Qt. And I used several C++ libraries in my work such as : boost, poco, pantheios and opencv. I am not aiming for cross-platform now, so I use Qt environment with Microsoft Visual C++ 2008 compiler and I can use my already compiled libraries in the new Qt-based application.

Here is some issue that I encounter during my attempt to integrate Qt with my VC++ libraries and how I fixed it.

  1. sigslot ’emit’ errors. in my projects, I used sigslot a lot. sigslot is a C++ signal/slot library, written to follow Qt signal/slot style. Using sigslot make code cleaner and modular, which is what you want in your code. Since ’emit’ is Qt keyword, all function named ’emit’ in sigslot.h must be replaced. In my case, I replace all ’emit’ words in sigslot.h into ‘semit’.
  2. implicit linking libraries path. boost, poco and pantheios use implicit linking. You don’t have to specify explicitly what lib file you want to use in your project, you just need to include the header in your code and specify the library’s lib folder in linking phase, then it will link automatically to libraries that use used. You have to use keyword QMAKE_LIBDIR in your Qt .pro file to add the path. For example : QMAKE_LIBDIR += $(BOOST_LIB). Note that BOOST_LIB is defined in environment path.
  3. If one of your library dynamically linked to MFC, you need to add MFC definition into qmake system. you can do this by adding DEFINES += _AFXDLL into your .pro file. Additionally, you might need to add DEFINES -= UNICODE, in case you have libraries that not build with unicode character (as in my case, pantheios).
  4. debug and release build. I spent three hours trying to figure out why release build always crash at startup. After googling, modify .pro and rebuild, I finally realized the release build use debug libs. This is how I did it wrong

This is in my .pro

debug {
LIBS += -L$(OPENCV)\lib -lcv210d -lcxcore210d -lhighgui210d -lml210d
}

release {
LIBS += -L$(OPENCV)\lib -lcv210 -lcxcore210 -lhighgui210 -lml210
}

I notice, that if I comment out the release libs part, I still compiled release build successfully, meaning that it uses debug libraries and resulted in crash. After googling, I found the solution. I change my .pro file :

CONFIG += debug_and_release

CONFIG(debug, debug|release) {
LIBS += -L$(OPENCV)\lib -lcv210d -lcxcore210d -lhighgui210d -lml210d
}

CONFIG(release, debug|release) {
LIBS += -L$(OPENCV)\lib -lcv210 -lcxcore210 -lhighgui210 -lml210
}

So to summarize, this is part of my .pro file

DEFINES -= UNICODE
DEFINES += _AFXDLL

CONFIG += debug_and_release

INCLUDEPATH += $(BOOST_INCLUDE)
INCLUDEPATH += $(OPENCV)\include

QMAKE_LIBDIR += $(BOOST_LIB)

CONFIG(debug, debug|release) {
    LIBS += -L$(OPENCV)\lib -lcv210d -lcxcore210d -lhighgui210d -lml210d
}

CONFIG(release, debug|release) {
    LIBS += -L$(OPENCV)\lib -lcv210 -lcxcore210 -lhighgui210 -lml210
}

And now my Qt GUI ready to use all my previous libraries. As you see below, the Qt based app is still far from MFC shown above in term on visual, but I can guarantee, the code is prettier. That’s what important, right ?

Qt based UI

Qt based UI

Some terms :
GUI : Graphical User Interface, and for those who don’t really understand this, it’s everything that you see in your PC or mac is GUI, except the command line.
MFC : Microsoft Foundation Classes, one of main developer framework from Microsoft, before .NET and now, WPF.
Qt : A cross-platform application and UI framework. It has two license, LGPL and commercial.  Developed by trolltech, now owned by Nokia, then Digia for the commercial licensing.

Advertisements

qt nokia apps part 2

Continue my latest post on qt apps that I wrote, there are more apps that I wrote to test new technique for handling page transition and another one just to have fun because I will install it if I have Nokia N8 (my company has, and if they feel I need it, they will let me abuse it)

Netflix Browser

My lead want me to write new code for page transition. Basically, what we have done is put all pages in a stack and show a page every time we change it. If you see previous part on tweeroo, it has 4 pages for home, timeline, single tweet and web. At the app initialization, all pages are created and then push into a stack. If you get confused by this, imagine putting four sheets of paper as a stack. If we need to show, for instance, timeline, then we move timeline to the top of the stack. Now we want to do another approach : only one page created at a time, no stack, If I want to show timeline page, I will create the page do transition and destroy previous page. Which one is better and efficient in term of memory usage and smooth user experience? I have to do more tests to see it.

Using netflix odata service, one can query movie list easily. And after one and a half day coding withQt and designing the look using Photoshop, this is what I got.

 

netflix

 

netflix

Anima

I always fascinated by animation world, name pixar, studio ghibli and many others who created great and amazing animation in 2D or 3D. I want to learn, but my art sense is below average. Regardless, I felt it would be nice if I have simple animation creator on Nokia smartphone. So I wrote Anima (short for animation, of course).

anima

anima

Anima is simple app where you can draw and then move to next frame and draw again, and then when you have enough frames, you can play your frames. Honestly, I thought paper and pencil is a great way to start learning animation. But we are living in digital age, or so they say, and I want to learn Qt, remember?

anima

anima : empty frame and onion skinning mode

Currently, save only for one document, so it will overwrite the old one, I need to create page and then do transition if I want to make document list, because using Qt file dialog will ruin the experience. Anima also has onion skinning mode, which let you see previous image so you have guide for current frame drawing. It only has one simple pen with black color. Currently Anima cannot create video, I still need to explore how to create video using Qt.

I have plan to make Anima into full featured application with more features such as layers, color, brush,  create video and also upload video into youtube.

qt nokia apps part 1

Starting from January this year, I started to work in mobile development using Nokia Qt SDK. My work primarily to test some new techniques because we already has one lead programmer. During the time, I have created several applications to learn Qt. I primarily worked with Qt C++ and maybe will explore QML in near future. These applications will not be released under the company that I work and if I have time or willingness to finish the basic feature and polish my ‘amateur’ software look, maybe I’ll publish one on Nokia Ovi store.

Someone might wonder why I still work on Qt, after Nokia and Microsoft partnership clearly stated that in the future, Nokia smartphones will use WP7, not current Symbian or Meego. Well, WP7 on Nokia maybe released on 2012, in the meantime, lets have fun with Qt !.

Tweeroo

My first work is on Twitter API. The task is to understand twitter oauth and RESTful API. Google and you will find open source library names kQOauth which just what I need to complete the task. After sometime browsing and coding to add list-style view, page transition and embedding webpage, this is what I’ve done.

tweeroo

tweeroo : home, authorise, timeline, tweet

tweeroo

tweeroo : single tweet, retweet, reply and open webpage from tweet.

As a note, Ray Wenderlich is a great iPhone/iOS developer and has a great website http://www.raywenderlich.com/ which contains lots of tutorials on how to make games for iOS using cocos2d engine. Yes, I am learning iOS too :). Check it out.

Nokinome

If I have Nokia N8, this is one utility that I will definitely install. A metronome (as I am learning how to play guitar, a metronome will be very handy). Simple and very useful and easy to make too. use timer to update the needle and then play a tick sound.

nokinome

nokinome

Why I use C++

“Just because very few people can fly a Space Shuttle doesn’t mean we shouldn’t have spacecraft. Some of us are big boys, and we can handle C++ just fine, thank you ” (Scott Robert Ladd, software engineer and writer)

Recently, after long year claiming myself to be C/C++ programmer, I worked with C# and found how easy it was. Like the world is not fair and somehow in programming world C++ turn out to be most difficult programming language ever. And after 8 years since I started programming on my third year of undergraduate school, I still unable to label myself a C++ expert. Should I continue down this road? I mean, you should  ‘teach yourself programming in 10 years’, right ?

For start, STL (Standard Template Library) components I always use are string and vector. STL Vector is nice, you can user any data type on it and it never complains, which shows how great STL is. STL string because I do not want messy C type string management. Well, STL is huge library and there is a lot of things you can do provided that you are comfortable with template programming. Yet, I still afraid marching toward that path. So I never touch boost, which is a huge beast of C++ libraries and guess what? most of it are templates. There is more, one of the standard book in defining C++ excellency is Andrei Alexandrescu’s Modern C++ Design: Generic Programming and Design Patterns Applied. And most of it related with template programming.

I start to learn C/C++ when a friend of mine sparked the idea that we should make a game. That was about 8 years ago. After using most of my 1st and 2nd year in college playing PS games on PC emulator, making a game is an interesting and great idea. You have great story which is mixed of Final Fantasy, Chrono Cross, Xenogears. You start designing characters and cool weapons. You start doodling your great medieval-modern stream-punk style city. But how to realize it into a game that you can play? A simple game editor (forget the name), just don’t fit your big vision. So you open the pandora box of game making. And there you find mixture of talents needed from programmer, artist, story and many more. So I chose toward programming since I have absolutely no talent in drawing, but I learn a little bit of Maya at that time. So why I chose C++? because you can’t make a ‘real’ game like Assassin’s Creed in other language. You just can’t.

Time is ticking and I kind of diverted my path toward programming for research and development. Now I am considered myself as a senior programmer. And the experience of C# and demand of skills in professional work just seems do not fit the C++ language path that I take. Java more favorable in enterprise work and C# is the next. C and C++, well, still holding great on OS, lower level stuffs, opensource projects and ‘real’ game development. Hell, my favorite IDE, Microsoft Visual Studio 2010 is completely written in WPF now. Most of younger taking programming course choose to work with simpler languages such as Delphi or VB for desktop development and php for web. And my job opening on C++ junior programmer returning null.

masterminds

Masterminds of programming, great reading where you can find why we have so many language now

This ranting seems just me trying to justify my path. That is true. Several days ago I read an article written by Paul Graham that Lisp (written in 1958, the 2nd oldest programming language after Fortran) is one great language that every mainstream language that we know today (java, C#, Phyton and others) are trying to approach Lisp. And another interesing paragraph from his other article “Historically, languages designed for other people to use have been bad: Cobol, PL/I, Pascal, Ada, C++. The good languages have been those that were designed for their own creators: C, Perl, Smalltalk, Lisp.”

C++ new standard is coming out now and I started to use poco, a great portable C++ class libraries and next, I will learn template and start using boost following the natural progression of this journey to be one of the big boys. Deep down I hope C++ will be better and better. And I think my reason toward C++ choice is still valid for now, and that make me happy.