Software:
News ToolsReg Shops |
Cross platform development for Windows and Mac OS XKilling two birds with one stonePublished Sunday 19th November 2006 19:22 GMT Hands on I’ve been fascinated by cross-platform programming for more years than I care to remember, and my interest has recently been sharpened by the acquisition of a number of Apple Macs – both Intel and PPC (PowerPC). This article focuses primarily on some technical aspects of Qt, Trolltech’s cross-platform C++ toolkit which, as you may know, is the architectural core behind the KDE desktop on Linux. At the end, I show how easy it is to create a simple application without writing a line of code. Making a MOC-ery Of It All…One of the most interesting aspects of Qt is the signal-slot mechanism. This connects an event such as a button press, mouse-click etc., to a consumer of that event. Assuming that you’re familiar with C# (and by now, you jolly well should be!) you’ll know that the VS.NET form designer connects an event to its consumer by doing something like this: this.OKButton.Click += new System.EventHandler(this.OKButton_Click); Here, anytime the All fine and dandy, but not hugely portable unless you’re using the Mono C# compiler (more on that here). Qt’s creators wanted to be able to compile code using any reasonably modern, bog-standard C++ compiler. Accordingly, they created moc. Moc is a pre-processor which converts the special C++ “superset” used by Qt into plain-vanilla C++. Note: If this seems odd, then think back to 1983 and the advent of C++. Stroustrup’s original Cfront pre-processor effectively translated C++ into straight C, making the new language available on any platform with a decent C compiler. To get some idea of what moc does, (that’s Meta-Object Compiler, by the way) take a look at the following class declaration taken from Trolltech’s documentation:
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *parent = 0);
~MyClass();
signals:
void mySignal();
public slots:
void mySlot();
};
The
Most of the grungy-looking stuff you can see is provided by the all-important Note: Well, actually, it’s a tad more complex than that. You’ll notice that
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search