Results 1 to 5 of 5

Thread: QThreads - queued connections

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QThreads - queued connections

    I'm trying to pass on a QImage from a worker thread (renderingThread) to my main thread for painting. Most of the code I used are recycled from the Mandelbrot Example. However, I'm getting an error from the emitted signal from my rendering thread.

    In member function 'virtual void RenderingThread::run()' : error: no matching function for call to 'RenderingThread::renderedImage(QImage*)' candidates are: void RenderingThread::renderedImage(QImage&)

    I'm passing along a reference to a QImage and not a pointer. Even the call to my function takes a reference and not a pointer. Here's some codes.
    Qt Code:
    1. //webcam.cpp
    2. renderingThread = new RenderingThread(imagebuffer,waitcondition) //thread is given pointers to a buffer and a wait condition
    3.  
    4. qRegisterMetaType<QImage>("QImage");
    5. connect(&renderingThread, SIGNAL(renderedImage(QImage& )), this, SLOT(updatePixmap(QImage& )));
    6. connect(startButton, SIGNAL(clicked()), this, SLOT(startThreads()));
    7.  
    8. //renderingthread.h
    9. signals:
    10. void renderedImage(QImage& displayImage);
    11. private:
    12. QImage displayImage;
    13.  
    14. //renderingthread.cpp
    15. void RenderingThread::run(){
    16. while (!halt){
    17. //rendering process()...
    18. emit renderedImage(&displayImage);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 
    What could be wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThreads - queued connections

    You are passing a pointer:
    Qt Code:
    1. emit renderedImage(&displayImage);
    To copy to clipboard, switch view to plain text mode 
    To pass a reference simply do:
    Qt Code:
    1. emit renderedImage(displayImage);
    To copy to clipboard, switch view to plain text mode 
    The compiler will know it should pass a reference and not a copy by looking at the signature of the method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QThreads - queued connections

    Thanks. I guess I'm getting closer to my results however,
    Qt Code:
    1. emit renderedImage(displayImage);
    To copy to clipboard, switch view to plain text mode 
    is now giving me this error:
    undefined reference to 'RenderingThread::renderedImage(QImage&)'
    Last edited by freekill; 12th January 2010 at 04:43. Reason: highlighted error

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThreads - queued connections

    You either didn't declare the signal or you forgot the Q_OBJECT macro in your class header.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThreads - queued connections

    Quote Originally Posted by freekill View Post
    Qt Code:
    1. //webcam.cpp
    2. renderingThread = new RenderingThread(imagebuffer,waitcondition) //thread is given pointers to a buffer and a wait condition
    3.  
    4. qRegisterMetaType<QImage>("QImage");
    5. connect(&renderingThread, SIGNAL(renderedImage(QImage& )), this, SLOT(updatePixmap(QImage& )));
    To copy to clipboard, switch view to plain text mode 
    What could be wrong?
    renderingThread is already a pointer so &renderingThread is a pointer to pointer (type RenderingThread**) - I guess it is not what you want. Just pass renderingThread to connect() method.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Queued Signal Slot connections
    By SebastianBecker in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2009, 20:06
  2. Qt Mem Leak/growth with queued connections across threads?
    By chuckshaw in forum Qt Programming
    Replies: 8
    Last Post: 16th August 2008, 16:43
  3. Identifying QThreads
    By TheGrimace in forum Newbie
    Replies: 2
    Last Post: 18th March 2008, 16:39
  4. Qthreads
    By Sheetal in forum Qt Programming
    Replies: 5
    Last Post: 23rd March 2007, 11:12
  5. signals and events queued...
    By soul_rebel in forum Qt Programming
    Replies: 8
    Last Post: 12th May 2006, 13:32

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
  •  
Qt is a trademark of The Qt Company.