[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: MOC Generation and #preprocessor fields
From:       Nicolas Ternisien <nicolas.ternisien () gmail ! com>
Date:       2005-06-22 7:47:59
Message-ID: ccba71b50506220047779e99fd () mail ! gmail ! com
[Download RAW message or body]

OK, the first time I read you, I was unhappy, because my slot problem
is in my main class, and 2 different headers would be _really_
annoying, but here is my final solution, if someone has this problem :

----------------------------------------------------------------------
1 header file :

class BigClass {

private:
CompatibilitySlotClass* compat;

}

----------------------------------------------------------------------
2 header file for the CompatibilitySlotClass :

First header : (compatibility.h)
class CompatibilitySlotClass {
   Q_OBJECT

   CompatibilitySlotClass(BigClass* class);

  public slots:
    void activate();

  private:
   BigClass* class;
}

----------------------------------------------------------------------
Second header : (compatibility-old.h) :

class CompatibilitySlotClass {
   Q_OBJECT

   CompatibilitySlotClass(BigClass* class);

  public slots:
    void activate(KAction::ActivationReason, Qt::ButtonState);

  private:
   BigClass* class;
}

----------------------------------------------------------------------
In the bigclass.cpp file :

#ifdef VERSION
  #include "compatibility.h"
#else
  #include "compatibility-old.h"
#endif


.....

compat=new CompatibilitySlotClass(this);
#ifdef VERSION
  connect(action, activated(KAction::ActivationReason,
Qt::ButtonState), compat, activate(KAction::ActivationReason,
Qt::ButtonState));
#else
  connect(action, activated(), compat, activate());
#endif


----------------------------------------------------------------------
And finally "compatibility.cpp" file :

#ifdef VERSION
  #include "compatibility.h"
#else
  #include "compatibility-old.h"
#endif

#ifdef VERSION
 void CompatibilitySlotClass::activate(KAction::ActivationReason
reason, Qt::ButtonState state) {
   //To manage from BigClass the signal, call a simple method of
BigClass with its pointer
  //This method will exist depending of the version, with preprocessor
entry, like here
  class->activate(reason, state);
  }
#else
 void CompatibilitySlotClass::activate() {
   //To manage from BigClass the signal, call a simple method of
BigClass with its pointer
  //This method will exist depending of the version, with preprocessor
entry, like here
  class->activate();

  }
#endif


#ifdef VERSION
  #include "compatibility.moc"
#else
  #include "compatibility-old.moc"
#endif


And you win !

One dummy MOC file will always be generated for nothing, but the false
one will never be compiled, and will not generate compilation problem.
You separate the management of this slot from your main class, to
avoid having 2 big headers and must merge them (everybody is not very
good with patch merging) each time you modify your main class.

Thanks for everyone to solve my problem.

Nicolas Ternisien.

PS: This mail is now a Qt Design Pattern ;-)
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic