Results 1 to 2 of 2

Thread: local variables in QThread - derived class

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default local variables in QThread - derived class

    My current understanding is that variables that are created in the constructor of the QThread-derived class will nevertheless be created in the context of the thread that created the instance of such class. For example, in the case below variable "a" is created in the context of main thread, but variable "b" is created in the context of the thread "threadOne". Is my understanding correct?

    Qt Code:
    1. class threadOne : public QThread
    2. {
    3. QString* a;
    4. QString* b;
    5. public:
    6. threadOne() {
    7. a = new QString();
    8. }
    9. private:
    10. void run() {
    11. b = new QString();
    12. }
    13. }
    14.  
    15. void main() {
    16. threadOne thread;
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: local variables in QThread - derived class

    Yes, as the constructor is run by the thread that creates the threadOne object but run() is being executed on the new thread.

    Cheers,
    _

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

    TorAn (4th September 2016)

Similar Threads

  1. Replies: 0
    Last Post: 4th May 2015, 04:48
  2. Replies: 2
    Last Post: 16th September 2013, 10:57
  3. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  4. Replies: 1
    Last Post: 21st June 2010, 07:26
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

Tags for this Thread

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.