PDA

View Full Version : error when adding signal slot to a QGLWidget based class



john_god
11th April 2009, 21:45
I have a QGLWidget based class that worked fine untill I add a signal slot
connection, so I can use a context menu, like the menu example in Qt assitant (only I'm
using it in a QGLWidget instead of the main window).
My class:


#include <QGLWidget>
#include <QMenu>
#include <QObject>

class GLGraph : public QGLWidget
{
// Q_OBJECT // this line causes the error

public:
GLGraph();
~GLGraph();
.....
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);

...
private:
.....
void createActions();
QAction *newInterpolAct;
....
private slots:
void newInterpol();



void GLGraph::contextMenuEvent(QContextMenuEvent *event)
{
if (!flag_Interpolation)
return;

QMenu menu(this);
menu.addAction(newInterpolAct);
menu.exec(event->globalPos());
}

void GLGraph::createActions()
{
newInterpolAct = new QAction(tr("&New"), this);
newInterpolAct->setShortcuts(QKeySequence::New);
// newInterpolAct->setStatusTip(tr("Create a new Interpolation"));
connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
}

void GLGraph::newInterpol()
{
QMessageBox::about(this,"","nova interpol");

}

My errors:


D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
D:/qt4examples/Matematica/glgraph.cpp:41: undefined reference to `vtable for GLGraph'
D:/qt4examples/Matematica/glgraph.cpp:41: undefined reference to `vtable for GLGraph'
:-1: error: collect2: ld returned 1 exit status


The error occurs when I use Q_OBJECT in the class declaration. The lines 9 and 41 are
the first bracket lines of the construtor and destructor. If I remove the Q_OBJECT the
program works, the context menus apears but doesnt connect and I get a message in the
Qtcreator compile output window:


Object::connect: No such slot QGLWidget::newInterpolAct() in glgraph.cpp:439

this line is:


connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));


Any ideas on this error ???????????

wysota
11th April 2009, 22:41
Always run qmake after adding the macro to an existing file.

john_god
11th April 2009, 23:31
THANK YOU very much :D:D:D:D

Also had other stupid mistake, I had:


connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));

instead of:

connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpol()));


Works fine now !!!!!