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>
{
// Q_OBJECT // this line causes the error
public:
GLGraph();
~GLGraph();
.....
protected:
...
private:
.....
void createActions();
....
private slots:
void newInterpol();
#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();
To copy to clipboard, switch view to plain text mode
{
if (!flag_Interpolation)
return;
menu.addAction(newInterpolAct);
menu.exec(event->globalPos());
}
void GLGraph::createActions()
{
newInterpolAct
= new QAction(tr
("&New"),
this);
// newInterpolAct->setStatusTip(tr("Create a new Interpolation"));
connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
}
void GLGraph::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");
}
To copy to clipboard, switch view to plain text mode
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
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
To copy to clipboard, switch view to plain text mode
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
Object::connect: No such slot QGLWidget::newInterpolAct() in glgraph.cpp:439
To copy to clipboard, switch view to plain text mode
this line is:
connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
To copy to clipboard, switch view to plain text mode
Any ideas on this error ???????????
Bookmarks