Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, December 2007
is it possible to have signals as defines ?


Message 1 in thread

having this:

#define ADD_LOG_FEATURES \
        signals: \
            void emitLogInfo( QString infoMessage ); \
            void emitLogWarning( QString warningMessage ); \
            void emitLogError( QString errorMessage ); \
            void emitLogFatal( QString fatalMessage );


I have a class where I do this:
class MyCalss : public QCoreApplication
{
    Q_OBJECT
   
   ADD_LOG_FEATURES

public:
    MyClass( int argc, char** argv );
    ~MyClass();

    ........
};



And as a result I get this:

out/myclass.o(.gnu.linkonce.t._ZN3MyClass7logInfoE7QString+0x22): In 
function `bool operator< <QString, unsigned short>(QPair<QString, 
unsigned short> const&, QPair<QString, unsigned short> const&)':
/usr/home/nicu/qt/debug-shared-sql-plugin/include/QtCore/qstring.h:791: 
undefined reference to `MyClass::emitLogInfo(QString)'
*** Error code 1 (continuing)

/usr/home/nicu/qt/debug-shared-sql-plugin/include/QtCore/qstring.h 
undefined reference to `MyClass::emitLogInfo(QString)'


Any ideas ?

--
 [ signature omitted ] 

Message 2 in thread

On 08.12.07 22:26:14, Yong Taro wrote:
> having this:

No thats not possible, moc doesn't support macro's and moc is the app
that create the code for the signal-functions.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

> #define ADD_LOG_FEATURES \
>         signals: \
>             void emitLogInfo( QString infoMessage ); \
>             void emitLogWarning( QString warningMessage ); \
>             void emitLogError( QString errorMessage ); \
>             void emitLogFatal( QString fatalMessage );

Wouldn't you be better off creating a pure virtual "log" class and
inheriting from that so that you get the signals for "free"?

A

--
 [ signature omitted ] 

Message 4 in thread

On søndag den 9. December 2007, Adam Hawes wrote:
> > #define ADD_LOG_FEATURES \
> >         signals: \
> >             void emitLogInfo( QString infoMessage ); \
> >             void emitLogWarning( QString warningMessage ); \
> >             void emitLogError( QString errorMessage ); \
> >             void emitLogFatal( QString fatalMessage );

Change this to

  enum LogLevel { Info, Warning, Error, Fatal };

signals:
  void emitLog( LogLevel level, const QString& infoMessage );

This way you at least only have to implement one method, and if you add new 
log levels they will automatically be supported. You can put the enum in some 
shared class or namespace.

Always change the specs instead of following them blindly, when there is an 
implementation detail that wasn't thought of when the specs were made.

> Wouldn't you be better off creating a pure virtual "log" class and
> inheriting from that so that you get the signals for "free"?

You can't create a pure virtual class that has signals or slots. The 
declaration of these includes creation of methods and subclassing QObject.

However, you might use interfaces. Search for Q_INTERFACES in assistant for a 
description on how to do this. It's intended for plugins, but I don't see why 
it wouldn't work here as well.

Bo.

-- 
 [ signature omitted ]