Results 1 to 5 of 5

Thread: Invoke UI functions from a different thread ?

  1. #1
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question Invoke UI functions from a different thread ?

    greetings all,

    I execute my intensive process using "QConcurrent::run()" , within that process I need to call UI methods (update(),repaint() ..etc) to update and draw the graph according to the calculations.

    But ,when I call repaint() , it throws "QPixmap: It is not safe to use pixmaps outside the GUI thread"

    and for update() , I dont get the desired output.

    Whats the best way to call UI methods from another thread?

    thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Invoke UI functions from a different thread ?

    Create a signal to update the user interface from within the main thread.

    Thus:
    Your worker thread emits a signal, a slot in your mainwindow or widget etc... reacts to this signal a performs a repaint or update.

  3. The following user says thank you to tbscope for this useful post:

    umanga (27th May 2010)

  4. #3
    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: Invoke UI functions from a different thread ?

    Use signals and slots to inform the main thread it should perform some graphical operation.
    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. The following user says thank you to wysota for this useful post:

    umanga (27th May 2010)

  6. #4
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Invoke UI functions from a different thread ?

    thanks tbscope for the reply,

    I can define the slot but how do I define the signal in the thread because I use QConcurrent::run() .
    Do I have to extends QThread class and define it?

  7. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Invoke UI functions from a different thread ?

    When you use run, you pass a function.
    In that function emit the signal.

  8. The following user says thank you to tbscope for this useful post:

    umanga (27th May 2010)

Similar Threads

  1. When and where to invoke QAbstractItemView::setIndexWidge?
    By mallun.wang in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2009, 10:48
  2. Invoke QCompletion on keyboard shortcut
    By aspidites in forum Qt Programming
    Replies: 0
    Last Post: 30th August 2009, 11:32
  3. Can we invoke other lang. scripts through QT
    By yogeshkarpate in forum Newbie
    Replies: 1
    Last Post: 14th August 2009, 11:43
  4. How to invoke a running application
    By srikanthch in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2008, 16:42
  5. Invoke a slot by its name in QString...
    By sunil.thaha in forum Qt Programming
    Replies: 4
    Last Post: 6th April 2006, 10:28

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.