Symbian code should be separated from Qt code so that it can be replaced with another platform-specific code when changing the platform. Private implementation (aka pimpl) is an idiom that is used in Qt, and it can be utilised to separate platform-specific code — different platforms have different implementations of the private class.
The QtS60AOExample in Active object example has a wrapper class that has an Symbian platform-specific private implementation. The main principles for private implementation are:
AOWrapper::AOWrapper(QObject *parent)
: QObject(parent)
{
d_ptr = new AOWrapperPrivate(this);
}
The constructor of the private class creates a pointer to the public class passed as a parameter:
AOWrapperPrivate::AOWrapperPrivate(AOWrapper *wrapper)
: q_ptr(wrapper)
{
}
The q_ptr pointer can be used to refer to the public class from the private class and the d_ptr pointer can be used to refer to the private class from the public class.
There is also a non-Symbian implementation of the private class in the example to show how the cross platform implementation can be done. There are source and header files for private class implementations that are added to the project based on the platform:
symbian: {
HEADERS += aowrapper_s60_p.h
SOURCES += aowrapper_s60.cpp
} else {
HEADERS += aowrapper_stub_p.h
SOURCES += aowrapper_stub.cpp
}
The idea of cross-platform implementation is to have the public interface of the class the same for all platforms; the private implementation can then be platform specific.