There's no real reason for CComListener to be a QObject if it is just an abstract interface. The public functions in the interface class can be treated as slots in the derived class For example, this seems to work:
#include <QtGui>
#include <QDebug>
// Class is abstract by virtue of having at least one pure virtual
class IComLineObserver
{
public:
explicit IComLineObserver() {}
virtual ~IComLineObserver() = 0;
// these can be slots in derived classes
virtual void OnTxLine
( QString sLine
) {} virtual void OnRxLine
( QString sLine
) {} virtual void OnRxChar
( QString sLine
) {} virtual void test() {}
};
IComLineObserver::~IComLineObserver() {}; // must have an implementation
class A
: public QObject,
public IComLineObserver
{
Q_OBJECT
public:
A() { }
~A() { }
public slots:
void test() { qDebug() << "Test"; }
};
int main(int argc, char *argv[])
{
A a;
QObject::connect(&t,
SIGNAL(timeout
()),
&a,
SLOT(test
()));
t.start(1000);
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
// Class is abstract by virtue of having at least one pure virtual
class IComLineObserver
{
public:
explicit IComLineObserver() {}
virtual ~IComLineObserver() = 0;
// these can be slots in derived classes
virtual void OnTxLine( QString sLine ) {}
virtual void OnRxLine( QString sLine ) {}
virtual void OnRxChar( QString sLine ) {}
virtual void test() {}
};
IComLineObserver::~IComLineObserver() {}; // must have an implementation
class A: public QObject, public IComLineObserver
{
Q_OBJECT
public:
A() { }
~A() { }
public slots:
void test() { qDebug() << "Test"; }
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
A a;
QTimer t;
QObject::connect(&t, SIGNAL(timeout()), &a, SLOT(test()));
t.start(1000);
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks