EDIT: Okay I solved the problem myself, this is humiliating... There was no instance of MainWindow
created in py main()
but I used the Widget itself as window -.-
I'm playing around a bit with OpenGL in Qt using the QGLWidget (Qt Version 5.3). My problem is the following: I have a class PaintWidget
that derives from QGLWidget
. In its PaintWidget::mousePressEvent(QMouseEvent*)
I read some value from the stencil buffer and want to send this via an emit
to the MainWindow
. The signal is implemented as
class PaintWidget : public QGLWidget {
Q_OBJECT
signals:
void objectClicked(int id);
public:
PaintWidget(QWidget* parent = 0);
...
}
and the mousePressEvent
method look
void PaintWidget::mousePressEvent(QMouseEvent* event) {
GLuint id;
glReadPixels(event->x(), m_height - event->y(), 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_INT, &id);
if (id > 0) {
emit objectClicked((int)id);
}
}
Now when I connect this signal to a slot inside of PaintWidget
everything works as expected, meaning the slot is called. But when I connect it to some slot of my MainWindow it doesn't work. The MainWindow
's constructor is:
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
m_paintEngine = PaintEngine::instance();
m_paintWidget = new PaintWidget();
connect(m_paintWidget, SIGNAL(objectClicked(int)), this, SLOT(dummy(int)));
setCentralWidget(m_paintWidget);
}
Here, dummy
is a public slot and it is newer called. Why doesn't this work?
Thanks, Michael