PDA

View Full Version : Signal/Slot connection problem



nightroad
6th April 2011, 08:00
Hi there ,

I have a QThread which is worker thread that supllying some data to QGLWidget. I made a signal completed on QThread. I wanna connect that signal with QGLWidget its DrawME Slot is it posssible to connect these Object with this way ?


class myThread : public QThread
{
public:
myThread(MainWindow *that) : QThread(0) {
m_MW = that; // i'm getting MainThread with that way i guess it's not good way ....
}

void run()
{
...
...
BYTE *pDib = (BYTE *)m_MW->myImage->imageData;
int w = m_MW->myImage->width;
int h = m_MW->myImage->height;
emit (completed(pDib,w,h));
}

signals:
void completed(BYTE *, int, int){}

private :
MainWindow *m_MW;
};

GLWidget


class GLWidget : public QGLWidget
{
Q_OBJECT

public:
GLWidget(QWidget *parent = 0);
void setTextureData(BYTE *data, int width, int height);

public slots:
void DrawME(BYTE * data, int width, int height);

private:
void initializeGL();
void resizeGL(int w, int h);
GLuint m_pTextureId;
};




myThread *t = new myThread(this);
QObject::connect(t, SIGNAL(completed(BYTE*,int,int)), ui->widget, SLOT(DrawME(BYTE*,int,int)));
t->start();


after t->start it works well signal is emitting but Slot DrawMe is not working , Could you gimme right way for connection slot and signals , thanks for help

ChrisW67
6th April 2011, 08:14
Remove the braces from line 19 of listing 1: moc generates the implementation of the signal for you and this implementation is probably interfering.

Other than that nothing seems out of place to me with the signal/slot connection.

How do you know the signal is being emitted if the slot is not being called?

nightroad
6th April 2011, 09:30
Remove the braces from line 19 of listing 1: moc generates the implementation of the signal for you and this implementation is probably interfering.

Other than that nothing seems out of place to me with the signal/slot connection.

How do you know the signal is being emitted if the slot is not being called?

Thanks for quick reply , i need body at line 19 so i need these braces. if i remove them it won't compile project, how do i know emitting simply i used break point at line 19 so my cursor going there , signal is emitting but slot is not working.

Added after 29 minutes:

When i was debugging i noticed sometihng like that on connect line ; "Object::connect: No such signal QThread::completed(BYTE*,int,int)" what the hell is that ?

Added after 16 minutes:

oh i forgot Q_OBJECT macro it's all my fault sorry about that ...