Results 1 to 4 of 4

Thread: Reading widgets from thread

  1. #1
    Join Date
    Jun 2009
    Location
    Poland, Wroclaw
    Posts
    2
    Thanks
    1
    Qt products
    Qt4

    Question Reading widgets from thread

    Hi

    I'm just wondering if doing something like widget->value() to read value is possible in thread. I'm just asking because doing it with signal/slots is a bit cumbersome.

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

    Default Re: Reading widgets from thread

    No, it's not possible. You can operate on widget from the main thread only. You have to use events or signals to transfer widget related data across threads.
    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. The following user says thank you to wysota for this useful post:

    sirlore (24th June 2009)

  4. #3
    Join Date
    Jun 2009
    Location
    Poland, Wroclaw
    Posts
    2
    Thanks
    1
    Qt products
    Qt4

    Default Re: Reading widgets from thread

    Quote Originally Posted by wysota View Post
    No, it's not possible. You can operate on widget from the main thread only. You have to use events or signals to transfer widget related data across threads.
    thanks for fast reply.

    I must say I was reading widgets in threads by just using pointers, as mentioned before, but any modification such as widget->setValue was made in main thread using signals slots. I haven't noticed any error or crush of my apps so far using this "method" of accessing widgets. There is no word about reading widgets "this way" in qt documentation, nor strict forbidding this.

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

    Default Re: Reading widgets from thread

    Quote Originally Posted by sirlore View Post
    There is no word about reading widgets "this way" in qt documentation, nor strict forbidding this.
    To quote the docs:
    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
    Reading is "quite safe" most of the time in general. In most cases the worst thay may happen is that you get a wrong value. Notice the "in most cases" part... Of course you might be satisfied with your application working correctly "in most cases".
    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.


Similar Threads

  1. Adding new Widgets in a seperate thread
    By Cruz in forum Qt Programming
    Replies: 7
    Last Post: 16th January 2009, 18:20
  2. IPC / reading stdin within non-GUI thread
    By mule in forum Qt Programming
    Replies: 3
    Last Post: 29th November 2007, 22:11
  3. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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.