Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QMediaControlNotifier Class Reference
[QtMediaModule]

The QMediaControlNotifier class watches a media content object for the availability of a given media control. More...

    #include <QMediaControlNotifier>

Inherits QObject.

Public Functions

Public Slots

Signals

Additional Inherited Members


Detailed Description

The QMediaControlNotifier class watches a media content object for the availability of a given media control.

When a control becomes available for the media content object the class emits a valid() signal. Similarly the class emits an invalid() signal when the control is not available.

The valid() signal indicates that the control for the media content object can be constructed and used immediately. The invalid() signal indicates that the control cannot be constructed and previously constructed controls of the same type for the media content object should no longer be used.

The following example defines a simple volume settings player object class that uses the QMediaControlNotifier and QMediaControl classes.

    class VolumeSettings : public QObject
    {
        Q_OBJECT
    public:
        VolumeSettings( QObject* parent = 0 )
            : QObject( parent ), control( 0 )
        {
            notifier = new QMediaControlNotifier( QMediaControl::name(), this );
            connect( notifier, SIGNAL(valid()), this, SLOT(activate()) );
            connect( notifier, SIGNAL(invalid()), this, SLOT(deactivate()) );
        }

        void setVolume( int volume )
        {
            if ( control )
                control->setVolume( volume );
        }

By convention all media controls have a static member function that returns a QString containing a name that identifies the control.

    public slots:
        void setMediaContent( QMediaContent* content )
        {
            notifier->setMediaContent( content );
        }

If a class contains other related player objects, rather than calling setMediaContent() directly on each, the notifier and related player objects could be grouped together using the QMediaContentContext class.

    private slots:
        void activate()
        {
            control = new QMediaControl( notifier->content() );
        }

        void deactivate()
        {
            delete control;
            control = 0;
        }

    private:
        QMediaControlNotifier *notifier;
        QMediaControl *control;
    };

When a media control becomes invalid the results of interacting with that control are undefined. For player objects it is common practice to delete and set to null invalid control member variables.

QMediaControlNotifier is a player object.

See also QMediaContent.


Member Function Documentation

QMediaControlNotifier::QMediaControlNotifier ( const QString & control, QObject * parent = 0 )

Constructs a control notifier to watch for the availability of control. By convention all controls have a static member function that returns a QString containing a name that identifies the control.

    QMediaControlNotifier *notifier = new QMediaControlNotifier( QMediaVideoControl::name(), this );

The parent argument is passed to the QObject constructor.

QMediaControlNotifier::~QMediaControlNotifier ()

Destroys the notifier.

QMediaContent * QMediaControlNotifier::content () const

Returns the media content which the notifier is currently watching.

void QMediaControlNotifier::invalid ()   [signal]

The control that the notifier is watching for is no longer avaiable and controls of that type previously constructed for the media content object are invalid.

void QMediaControlNotifier::setMediaContent ( QMediaContent * content )   [slot]

Sets content as the media content to watch.

If the control that the notifier is watching for is currently vaild for the previous media content object, an invalid() signal will be emitted.

void QMediaControlNotifier::valid ()   [signal]

The control that the notifier is watching for is available and controls constructed of that type for the media content object will be valid.


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3