Results 1 to 3 of 3

Thread: Signal/Slot connection problem

  1. #1
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Angry Signal/Slot connection problem

    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 ?

    Qt Code:
    1. class myThread : public QThread
    2. {
    3. public:
    4. myThread(MainWindow *that) : QThread(0) {
    5. m_MW = that; // i'm getting MainThread with that way i guess it's not good way ....
    6. }
    7.  
    8. void run()
    9. {
    10. ...
    11. ...
    12. BYTE *pDib = (BYTE *)m_MW->myImage->imageData;
    13. int w = m_MW->myImage->width;
    14. int h = m_MW->myImage->height;
    15. emit (completed(pDib,w,h));
    16. }
    17.  
    18. signals:
    19. void completed(BYTE *, int, int){}
    20.  
    21. private :
    22. MainWindow *m_MW;
    23. };
    To copy to clipboard, switch view to plain text mode 

    GLWidget

    Qt Code:
    1. class GLWidget : public QGLWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. GLWidget(QWidget *parent = 0);
    7. void setTextureData(BYTE *data, int width, int height);
    8.  
    9. public slots:
    10. void DrawME(BYTE * data, int width, int height);
    11.  
    12. private:
    13. void initializeGL();
    14. void resizeGL(int w, int h);
    15. GLuint m_pTextureId;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. myThread *t = new myThread(this);
    2. QObject::connect(t, SIGNAL(completed(BYTE*,int,int)), ui->widget, SLOT(DrawME(BYTE*,int,int)));
    3. t->start();
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Signal/Slot connection problem

    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?

  3. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Signal/Slot connection problem

    Quote Originally Posted by ChrisW67 View Post
    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 ...
    Last edited by nightroad; 6th April 2011 at 09:30.

Similar Threads

  1. Signal/Slot connection failing
    By Polnareff in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2010, 20:41
  2. Signal and Slot connection not working !!
    By prakash437 in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2010, 10:16
  3. Signal and slot connection graph
    By fahlen in forum General Discussion
    Replies: 4
    Last Post: 27th November 2007, 13:47
  4. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 19:22
  5. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 13:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.