| Home · All Classes · Annotated · Functions |
The QCopObjectService class provides an interface to messages on a QCop service which simplifies remote slot invocations More...
#include <QCopObjectService>
Inherits QCopObject.
Inherited by AlarmService, AlertService, CalendarService, CleanupWizardService, ClockService, ContactsPhoneService, ContactsService, DateService, DialerService, EmailService, HelpService, LauncherService, PhotoEditService, ProfilesService, QDLService, QtopiaService, ScreenSaverService, SettingsManagerService, SettingsService, SMSService, TaskManagerService, TasksService, TimeMonitorService, TimeService, VoiceRecordingService, and WebAccessService.
The QCopObjectService class provides an interface to messages on a QCop service which simplifies remote slot invocations
The QCopObjectService class provides an interface for sending messages on a QCop service which simplifies remote slot invocations. It differs from QCopObject in that the channel name is derived from the name of a service, allowing the application that implements the service to be determined at runtime.
The use of this class will be demonstrated using the Qtopia Time service. This has a single message called editTime() which asks the service to pop up a dialog allowing the user to edit the current time.
On the server side, the easiest way to obtain notification of the request is to connect the message to a local slot.
QCopObjectService *service = new QCopObjectService( "Time", this );
QCopObject::connect( service, MESSAGE(editTime()), this, SLOT(showTime()) );
This code arranges for QCop messages with the name Time::editTime() to be delivered to the application's showTime() slot.
Note: In previous versions of Qtopia, the message did not have the Time:: prefix. The prefixing convention has been introduced to resolve conflicts between services that may have requests with the same name.
The server may want to encapsulate a service in its own class:
class TimeService : public QCopObjectService
{
Q_OBJECT
public:
TimeService( QObject *parent = 0 );
public slots:
void editTime();
};
TimeService::TimeService( QObject *parent )
: QCopObjectService( "Time", parent )
{
publishAll();
}
The call to publishAll() causes all public slots within TimeService to be automatically registered as QCop service messages. This can be useful if the service has many message types.
The client can send a request to the service in a number of ways. The simplest is to use the QCopServiceRequest class, as in previous versions of Qtopia:
QCopServiceRequest req( "Time", "editTime()" );
req.send();
The Time:: prefix will be automatically added by QCopServiceRequest.
Clients can also use the QCopObjectService class to send the request, which will automatically add the prefix:
QCopObjectService serv( "Time" );
serv.send( MESSAGE(editTime()) );
Alternatively, clients can connect a local signal to the message and emit it whenever the service is required:
QCopObjectService *service = new QCopObjectService( "Time", this );
QCopObject::connect( this, SIGNAL(requestEditTime()), service, MESSAGE(editTime()) );
emit requestEditTime();
This version may be useful if a client will be making lots of requests to a service.
See also QCopService, QCopObject, QCopEnvelope, and QCopServiceRequest.
Construct a QCop message object for service and attach it to parent.
Destroy this QCop service handling object.
Publish all slots on this object within subclasses of QCopObjectService. This is typically called from a subclass constructor.
Use this instead of QCopObject::publishAll() for services, because it does not make sense for signals to be published via a QCop service.
Convert channel into a new name to use for receiving messages. This override returns an empty string, which indicates that messages should be received on the application's main message channel.
Reimplemented from QCopObject.
Convert channel into a list of new names to use for sending messages. This override interprets channel as a service name and looks up the actual QCop channels associated with the service.
Reimplemented from QCopObject.
| Copyright © 2006 Trolltech | Trademarks | Qtopia 4.1.7 |