Results 1 to 13 of 13

Thread: Render from a thread into a pixmap?

  1. #1
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Render from a thread into a pixmap?

    I have a thread which I use to render a QPixmap. Doing this I get errors from the Xlib. In this
    forum I've already read the cause is that the X server manages the pixmaps and threads should not access them.
    So I tried a QImage, which is pretty slow... I think it would be better to use no Thread and render in the GUI thread (which blocks), but is faster...

    Is there any way to render within the thread into this pixmap?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Render from a thread into a pixmap?

    You can only render to QImage from a worker thread and then you can convert it to a pixmap in the gui thread.

  3. #3
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Render from a thread into a pixmap?

    This is very sad, because drawing a QImage is so much slower...

    Is it possible to handle GUI events in another thread and do the expensive pixmap creation in the GUI thread? (Changing the tasks of the threads?) So the GUI should stay operable.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Render from a thread into a pixmap?

    Quote Originally Posted by rage View Post
    Is it possible to handle GUI events in another thread (...)
    No. GUI must be handled from the main thread. So do pixmaps as they are related to the X server.

    So the GUI should stay operable.
    It's best to redesign your code using timers or QCoreApplication::processEvents(). I'm almost sure you can do anything you need without threads or blocking the application.

  5. The following user says thank you to wysota for this useful post:

    rage (20th December 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render from a thread into a pixmap?

    Quote Originally Posted by rage View Post
    This is very sad, because drawing a QImage is so much slower...
    What do you draw exactly? And how much is "much"?

  7. #6
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Render from a thread into a pixmap?

    I combine up to nine RGB-images with a resolution of 256x256 each to one large image. I want to do this depending on user interaction multiple times a second. The combined QImage is created in the "worker" thread and gets converted to a pixmap in the GUI thread (by calling QPixmap::fromImage()). Here I draw it on the screen. The conversion from QImage to QPixmap with a resolution of eg 768x768 is the slowest operation I think.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Render from a thread into a pixmap?

    If you do it several times a second, I suggest you draw it to the screen without composing it first on an offscreen bitmap. Or even use OpenGL.

  9. #8
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Lightbulb Re: Render from a thread into a pixmap?

    Quote Originally Posted by wysota View Post
    If you do it several times a second, I suggest you draw it to the screen without composing it first on an offscreen bitmap. Or even use OpenGL.
    Currently I am playing with the QCoreApplication::processEvents() you mentioned. I think this could solve my problem. I am not using OpenGL, bacause the application should also run on Qtopia devices...

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render from a thread into a pixmap?

    Quote Originally Posted by rage View Post
    The conversion from QImage to QPixmap with a resolution of eg 768x768 is the slowest operation I think.
    It could be, but you have said that drawing on QImage is slower than drawing on QPixmap. Have you tried to use a profiler to check the times?
    Last edited by jacek; 20th December 2007 at 13:26. Reason: typo

  11. #10
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Render from a thread into a pixmap?

    Quote Originally Posted by jacek View Post
    I could be, but you have said that drawing on QImage is slower than drawing on QPixmap. Have you tried to use a profiler to check the times?
    Yes, I have done that with callgrind. The fromImage() call takes ~44% of the processing time.

  12. #11
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default [SOLVED] Render from a thread into a pixmap?

    Thanks wysota!
    I'm now rendering the QPixmap within the GUI thread, so I don't need QImages. By calling processEvents() it doesn't block. I'll just have to do some locking with mutexes and then everything should be fine!

  13. #12

    Default Re: Render from a thread into a pixmap?

    How rendering the QPixmap within the GUI thread? And how to do it won't be block?Would you mind write your handle?Thanks

  14. #13
    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: Render from a thread into a pixmap?

    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. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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.