Results 1 to 2 of 2

Thread: local variables in QThread - derived class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    US, Midwest
    Thanked 4 Times in 4 Posts
    Qt products
    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. }
    15. void main() {
    16. threadOne thread;
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    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.


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

    TorAn (5th September 2016)

Similar Threads

  1. Replies: 0
    Last Post: 4th May 2015, 05:48
  2. Replies: 2
    Last Post: 16th September 2013, 11: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, 15:53
  4. Replies: 1
    Last Post: 21st June 2010, 08:26
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 08:36

Tags for this Thread


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.