Results 1 to 4 of 4

Thread: QtConcurrent and QPainter

  1. #1

    Default QtConcurrent and QPainter

    Hello!

    I have a few problems I have been stuck on lately and was wondering if anyone could give me any answers or advice.

    1: Does Qt Concurrent::run, run the function passed in a seperate thread AND the functions called in that function? Or does it return to the main thread when a function is called in it?

    2: I am running a draw function in QtConcurrent (its purpose to create a plot). However after it runs several times it eventually leads to Painter is not active errors printed on the screen. After which none of the painters work anymore.
    What usually leads to these types of errors? I don't have the source on me and for that matter its very long and thick. But I was hoping I was missing something obvious. I know Pixmaps are not thread safe , so I have been using QImages. (As I've read this is a common mistake). Also no text is being rendered either.
    (And for those who use QWT im basically trying to make the drawCanvas function run in a separate thread, asyncronously)

    3: I understand widgets cannot be outside of the GUI thread but can you used functions from QWidget such as : contentsRect() outside the GUI thread?

    If anyone can give me any insight at all about any of these I'd greatly appreciate it =). Thanks.

  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: QtConcurrent and QPainter

    Quote Originally Posted by AwDogsgo2Heaven View Post
    1: Does Qt Concurrent::run, run the function passed in a seperate thread AND the functions called in that function? Or does it return to the main thread when a function is called in it?
    Everything is ran in a dedicated thread.

    2: I am running a draw function in QtConcurrent (its purpose to create a plot). However after it runs several times it eventually leads to Painter is not active errors printed on the screen. After which none of the painters work anymore.
    What usually leads to these types of errors?
    You can't access widges (and painting them in particular) from within external threads. That's the source of your problem. The same goes with pixmaps. Images are fine as long as you don't use fonts.

    3: I understand widgets cannot be outside of the GUI thread but can you used functions from QWidget such as : contentsRect() outside the GUI thread?
    Reading is quite safe. The worst that can happen is that you get an outdated value.
    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

    Default Re: QtConcurrent and QPainter

    My printing device is a QImage though. I dont believe im printing to any widges until the thread is complete. And no fonts are being used.

  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: QtConcurrent and QPainter

    We'd have to see the code to be able to tell anything more.
    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.


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.