# SWIG and QT (QT4\_WRAP\_CPP issues)

**URL:** <https://www.ruby-forum.com/t/swig-and-qt-qt4-wrap-cpp-issues/230489>\
**Category:** GNU Radio\
**Created:** [June 19, 2014, 11:32pm UTC](https://www.ruby-forum.com/t/swig-and-qt-qt4-wrap-cpp-issues/230489 "2014-06-19T23:32:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 19, 2014, 11:32pm UTC](https://www.ruby-forum.com/t/swig-and-qt-qt4-wrap-cpp-issues/230489/1 "2014-06-19T23:32:32Z")

</div>

Hi!

I try to add a QT GUI to my OOT module (gr-radar). I have some issues  
with including the QT stuff in cmake and swig.

The problem is this error:

## /gr-radar/swig/…/lib/range\_velocity\_diagram.h:45: Error: Syntax

error in input(3).

## make[2]: \*\*\* [swig/radar\_swigPYTHON\_wrap.cxx] Error 1

## make[1]: \*\*\* [swig/CMakeFiles/pygen\_swig\_9a820.dir/all] Error 2

The line 45 refers to

## public slots:

Whole class definition is appended.[0]

If I build my module without ‘public slots:’ line but WITH the Q\_OBJECT  
line everything runs fine and I get a new QT window. So I suppose that  
the additional class range\_velocity\_diagram is included correctly in  
cmake and swig. Also I think the Q\_OBJECT macro is accepted by cmake and  
swig.

I have looked at gr-qtgui and added QT4\_WRAP\_CPP to get the Q\_OBJECT  
macro running. My changes in CMakeLists.txt (lib directory):

set(QTGUI\_MOC\_HEADERS range\_velocity\_diagram.h)  
QT4\_WRAP\_CPP(QTGUI\_MOC\_OUTFILES ${QTGUI\_MOC\_HEADERS})  
add\_library(gnuradio-radar SHARED ${radar\_sources}  
${QTGUI\_MOC\_OUTFILES})

Do I need to add more to get swig running with the QT slots and signals?  
I am correct with the assumption that cmake and swig accepts the  
Q\_OBJECT macro?

Best regards  
Stefan

[0] Class definition range\_velocity\_diagram  
class range\_velocity\_diagram : public QWidget  
{  
Q\_OBJECT;

public:  
range\_velocity\_diagram();  
~range\_velocity\_diagram();

private:  
QwtPlot\* d\_plot;  
QwtPlotCurve\* d\_curve;

public slots:

};

---

<div class="post-metadata">

**Author:** ![Stefan\_Wunsch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/74df32/32.png) [@Stefan\_Wunsch](https://www.ruby-forum.com/u/Stefan_Wunsch)\
**Post date:** [June 20, 2014, 12:06am UTC](https://www.ruby-forum.com/t/swig-and-qt-qt4-wrap-cpp-issues/230489/2 "2014-06-20T00:06:24Z")

</div>

Hi,

> Do I need to add more to get swig running with the QT slots and signals?  
> I am correct with the assumption that cmake and swig accepts the  
> Q\_OBJECT macro?

Why do you even need to get those through swig ?

Last time I did a Qt block, all the Qt stuff was hidden from swig,  
there was only theses in the header :

* * *

```
  virtual void exec_() = 0;
  virtual QWidget* qwidget() = 0;

```

#ifdef ENABLE\_PYTHON  
virtual PyObject\* pyqwidget() = 0;  
#else  
virtual void\* pyqwidget() = 0;  
#endif

```
  QApplication *d_qApplication

```

* * *

and nothing more, all the rest was hidden and never went through swig.

Cheers,

Sylvain

---

<div class="post-metadata">

**Author:** ![Stefan\_Wunsch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/74df32/32.png) [@Stefan\_Wunsch](https://www.ruby-forum.com/u/Stefan_Wunsch)\
**Post date:** [June 20, 2014, 12:24am UTC](https://www.ruby-forum.com/t/swig-and-qt-qt4-wrap-cpp-issues/230489/3 "2014-06-20T00:24:49Z")

</div>

Sylvain solved it in a sec 😉 There is no need to get the classes with  
the qt stuff through swig. Solution is including the additional qt  
classes only in cmake and wrap them with QT4\_WRAP\_CPP cause of the  
Q\_OBJECT macro but dont care about them in the \*\_swig.i file.

Am 19.06.2014 23:31, schrieb Stefan Wunsch:
