WxQt

From WxWiki
Revision as of 09:43, 15 May 2010 by 93.203.246.120 (talk)
Jump to navigation Jump to search

Adding files

To add a Qt derived class simply put it in a .h file and add the corresponding .moc.cpp file to the buid/bakefiles/files.bkl e.g.:

<set var="QT_LOWLEVEL_HDR" hints="files">
    wx/qt/menuitem.h
</set>

<set var="QT_LOWLEVEL_SRC" hints="files">
    src/qt/menuitem.cpp
    src/qt/menuitem.moc.cpp
</set>

The build rule in build/bakefiles/qtrules.mk:

$(srcdir)/src/qt/%.moc.cpp: $(srcdir)/include/wx/qt/%.h
	moc $< -o $@

will then ensure that the .h file gets translated by the moc to a .moc.cpp file which will be compiled and linked like any other source file. You don't have to put it in a separate .h file, you can put it in the same header as the wx class, but you can't embed it in the .cpp file i.e.:

// include/wx/qt/menuitem.h

class wxMenuItem : public wxMenuItemBase
{
   // ...
};



class wxQtAction : public QAction
{
    Q_OBJECT

public:
    wxQtAction( wxMenuItem *menuItem, const QString &text, QObject *parent );

private Q_SLOTS:
    void OnActionTriggered( bool checked );

private:
    wxMenuItem *m_menuItem;
};

Coding guidelines

  • If you leave out an implementation for whatever reason, then mark it with the wxMISSING_IMPLEMENTATION() macro from wx/qt/utils.h i.e.:
void wxSomeClass::SomeMethod()
{
    wxMISSING_IMPLEMENTATION( __FUNCTION__ );
}

or if only some implementation is missing like evaluating flags:

void wxSomeClass::SomeMethod( unsigned methodFlags )
{
    wxMISSING_IMPLEMENTATION( "methodFlags" );
}
  • To avoid name clashes with a 3rd party library like boost, don't use the internal moc keywords 'signals' and 'slots' but the replacements Q_SLOTS and Q_SIGNALS i.e.:
class wxQtClass : public QClass
{
private Q_SLOTS:
    void OnSignal();
};

If you would like to discuss this 'guidelines' then you can contact me (Peter Most) on the developer mailing list.