Porting to OS/2: Case #18 Qt basic

Qt is a very powerful cross-platform framework. And it was ported to OS/2, but it is more or less old. Because the latest upstream version is 5.3, and OS/2 version is 4.7.3.

Nevertheless, Qt4 is still very powerful and useful. In addition, bww bitwise works, who is porting Qt to OS/2, has a plan to port Qt5 as well. So I recommend to use Qt if you have a plan to create GUI programs for OS/2 rather than native PM APIs. And this has another benefits. If you don't use specific codes to OS/2, then you can create a program for other platforms with minimum modifications. This is true when porting to OS/2. That is, if some programs have no specific codes to specific OSes, they can be ported to OS/2 easily. Based on this aspect, let's find basic ways to port programs using Qt to OS/2.

Basic procedures to build Qt-programs is like the following.

  1. qmake
  2. make

What a simple. But sometimes, some projects requires some tasks such as configure before qmake. Or, they may use other project tools instead of qmake. For deatils, refer to documents shipped with those projects.

For practice, download sample programs.


This is a measurement unit converter application. After downloading, extract it into somewhere. Then cd there. Now step the basic procedures. That is, qmake and make.

However, you will encounter the following error.

rc -n -r qmetrics.rc .\qmetrics.res
RC :(qmetrics.rc:1:1588559):Error 4009:Invalid or out of context statement encountered  [IDI_ICON1]
RC :(qmetrics.rc:1:1588597):Error 4000:Missing parameter [File Spec]
RC :(qmetrics.rc:1:1588597):Error 1009:RC detected errors during compilation.

This is due to a resource file, qmetrics.rc. qmetrics.rc is specific to Windows. If possible, it would be better to create a equivalent resource file for OS/2. But at this time, ignore it. How ?

Open a project file, qmetrics.pro. Then find [RC_FILE =] line. Remove that line. But more portable way is to use 'condition'. qmake has a predefined condition for platforms. win32 is for Win32 and os2 is for OS/2. For details, see qmake parts in Qt Assistant.

In this case, a rc file is specific to Win32, it should be evaluated only on Win32. So prepend [win32:] to that line. If '!' is prepended, it means 'not'. That is, !os2 means 'if not os2'. So [!os2:] may be used instead of [win32:].

Do qmake and make again. Now you can get the executable and execute it.

Finally, this program is very simple case. Sometimes, you should modify sources for OS/2 only. In these cases, you can use pre-defined macros for OS/2 such as Q_OS_OS2 for non-GUI sources and Q_WS_PM for GUI sources. And Qt for OS/2 is very similar to Qt for Windows. So it is very useful to refer to pre-defined macros for Win32. They are Q_OS_WIN32 and Q_WS_WIN32. Of course, some compiler specific macros such as WIN32 and _WIN32 may be used.

// ----- 2015/01/28

Using Windows icons


Above, we ignored a resource file for an icon. Here find the way to use it on OS/2.

First, before using it, we should convert Windows icons to OS/2 icons. Use WinIco v0.93 or later at hobbes or Icon Plus.

WinIco: winico qmetrics.ico qmetrics_os2.ico
Icon Plus: icplus qmetrics.ico qmetrics_os2.ico

Now create a .rc file for an OS/2 icon named qmetrics_os2.rc.

ICON 1 "qmetrics_os2.ico"

And modify the RC_FILE parts of qmetrics.pro like this.

win32 : RC_FILE = qmetrics.rc
os2 : RC_FILE = qmetrics_os2.rc

Then, execute qmake and make in order, again.

Unfortunately, however, the icon of the executable is corrupted. This is due to lxlite and rc. To workaround this, you need to embed .res file to .exe file once more after linking finishes like this.

rc qmetrics_os2.res qmetrics.exe

However, if you feel that this is somewhat complicated,  then just rename qmetrics_os2.ico to qmetrics.ico whose name is same as qmetrics.exe except an extension, and place both qmetrics.ico and qmetrics.exe at the same directory.

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷