Results 1 to 3 of 3

Thread: Regarding emit'ing signals from a thread (QT3)

  1. #1
    Join Date
    Jan 2006
    Location
    Rochester, NY
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Regarding emit'ing signals from a thread (QT3)

    I have an application which pulls image data from memory (provided by a shared library) and displays the image to the user. My appliation has two threads, the GUI thread and the worker thread which gets the image data.

    Right now when the worker thread gets all the data for an image I use emit to send the data (as a QByteArray) to the GUI thread. This does work, but I'm wondering if it's a good thing to do?

    Every now and then I get weird errors that seem to indicate that the worker thread is actually handling the display too (I had hoped emitting the data from the worker thread would cause it to be processed in the GUI thread).

    Basically, I'm wondering if this is the wrong approach to take. I've read that this works in QT4 (unfortunately I don't have the option of using QT4). Does anyone know if it works in QT3 as well?

    Thanks in advance.

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

    Default Re: Regarding emit'ing signals from a thread (QT3)

    This is the wrong approach to take if you wish to display that image

    Read this: http://doc.trolltech.com/3.3/threads.html

    Use custom events instead.

  3. #3
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Regarding emit'ing signals from a thread (QT3)

    If you have the Gui Programming with Qt3 book take a look at chapter 17, especially "Communicating with the GUI Thread".
    In a few words you can create a custom event that will have as a public member the array you want to send to the gui thread. Then whenever you want the gui to accept data you send the new event to the gui's enent handler from the worker thread using
    Qt Code:
    1. QApplication::postEvent()
    To copy to clipboard, switch view to plain text mode 
    and the array can then be handled from your gui thread.

    EDIT: Funny... Check out what happens if I don't wrap in [C O D E] tags: QApplication:ostEvent()
    EDIT2: With all this previewing and editing my post became obsolete. Anyway since you got the same answer twice it means that this is the way to go
    Last edited by yop; 6th January 2006 at 22:20.

Similar Threads

  1. Problem using signals and thread
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2008, 14:57
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  3. Replies: 10
    Last Post: 20th March 2007, 23:19
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49
  5. emiting signals from const member functions !?
    By sunil.thaha in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2006, 12:29

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.