Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Interfaces and Abstract classes

$
0
0
Hi I’ve just started writing a prototype to find out how certain things work in c++11/qt5. I’ve noticed that at least in c++ there is no keyword to achieve interfaces or abstract classes but one uses virtual methods instead. virtual void setValue (QString s) = 0; Qt seems to have a macro called something like Q_DEFINE_INTERFACE or something. But i’m not able to find any usable examples. So due to the lack of documentation i’m not sure if i’m doing it the right way. Since it is easy to run into problems later on i would like to hear some opinions about my approach. interface: #ifndef ICONTROLLABLE_H #define ICONTROLLABLE_H   #include <QObject>   class IControllable { public:   //explicit IControllable(QObject *parent = 0);   virtual ~IControllable () {}   virtual void start () = 0;   virtual void stop () = 0;   virtual void show () = 0;   virtual void hide () = 0; };   #endif // ICONTROLLABLE_H abstract base class: #ifndef PLAYERBASE_H #define PLAYERBASE_H   #include <QObject>   class PlayerBase : public QObject {   Q_OBJECT public:   QString source;     explicit PlayerBase(QObject *parent = 0);   virtual void setSource (QString source) = 0;   signals:   void playbackFinished (QString source);   };   #endif // PLAYERBASE_H concrete class: #ifndef VIDEOPLAYER_H #define VIDEOPLAYER_H   #include <QObject> #include "playerbase.h"   class videoPlayer : public PlayerBase {   Q_OBJECT public:     videoPlayer(); };   #endif // VIDEOPLAYER_H So how is it. Should my interface inherit form QObject too? Should i run the base (supercalss) constructor? May it be a problem that each of these classes inherit from QObject themselves? It would be nice if you could clarify my questions with some example code. I don’t really know yet how i run the super constructor for example.

Viewing all articles
Browse latest Browse all 18427

Trending Articles