Results 1 to 8 of 8

Thread: How define an interface for a Qt object

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How define an interface for a Qt object

    Ok so I changed so only the interface derived from QObject and the class inherit from the interface, like below. However I am not sure how to handle the passing of the parent object to the base class. I guess without this I will loose the memory managment, or? See comment in the source file below:

    #include <QObject>

    class ICallHandler : public QObject
    {
    public:
    virtual ~ICallHandler(){};

    public slots:
    virtual void onIncomingCall() = 0;
    };

    and for the class implementing the interface:

    #include <QObject>

    class CallHandler : public ICallHandler
    {
    Q_OBJECT

    public:
    CallHandler(QObject *parent);
    ~CallHandler();
    public slots:
    void onIncomingCall();
    };

    and for the source file:

    #include "callhandler.h"

    CallHandler::CallHandler(QObject *parent)
    : ICallHandler() //How handle the parent object here?
    {

    }

    CallHandler::~CallHandler()
    {

    }

    void CallHandler:nIncomingCall()
    {}

  2. #2
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How define an interface for a Qt object

    Make ICallHandler have a protected ctor which takes a QObject* as a parameter. Then in the ctor of CallHandler, pass the parent. For example:
    Qt Code:
    1. class ICallHandler : public QObject
    2. {
    3. public:
    4. virtual ~ICallHandler(){};
    5.  
    6. public slots:
    7. virtual void onIncomingCall() = 0;
    8.  
    9. protected:
    10. ICallHandler(QObject *parent = NULL) : QObject(parent) {}
    11. };
    To copy to clipboard, switch view to plain text mode 

    Then in the CallHandler ctor:
    Qt Code:
    1. CallHandler::CallHandler(QObject *parent)
    2. :
    3. ICallHandler(parent)
    4. {
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2013
    Posts
    1

    Default Re: How define an interface for a Qt object

    Is it possible to not have dependencies to Qt in the interface?

    For me the ICallHandler interface shall be independent of the UI.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How define an interface for a Qt object

    Quote Originally Posted by vince View Post
    Is it possible to not have dependencies to Qt in the interface?

    For me the ICallHandler interface shall be independent of the UI.
    If you don't use any Qt API in the interface then it will be independent of Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How define an interface for a Qt object

    Also QObject is a class of QtCore so it does not have any dependency on UI even when being used.

    Cheers,
    _

Similar Threads

  1. (ActiveQt) Invoking interface from COM object
    By mridulgandhi in forum Qt Programming
    Replies: 4
    Last Post: 11th October 2009, 20:29
  2. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 14:28
  3. tr with #define..it can work?
    By mattia in forum Newbie
    Replies: 9
    Last Post: 4th February 2008, 11:15
  4. #define MYCLASS_H ?
    By bnilsson in forum General Programming
    Replies: 1
    Last Post: 3rd February 2008, 10:50
  5. where should i put #define in QtDesigner?
    By nass in forum Qt Tools
    Replies: 1
    Last Post: 16th October 2006, 15:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.