Results 1 to 4 of 4

Thread: How to access parents variables

  1. #1
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default How to access parents variables

    Hi Folks,

    I don't get it. I have a QWidget and a QThread(*parent). Now the QWidget starts the QThread(*parent). In this QThread I want to access the variables in the QWidget. Imagine the QWidget holds an iserinput like QLineEdit.

    Finally I have two Headers:

    #1.
    Qt Code:
    1. #include ...
    2.  
    3. class UserInput : public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit UserInput(QWidget *parent = 0);
    8.  
    9. QLineEdit *inputLine;
    10. }
    To copy to clipboard, switch view to plain text mode 

    #2
    Qt Code:
    1. #include ...
    2.  
    3. class algorithmus : public QThread
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit algorithmus(QWidget *parent)
    To copy to clipboard, switch view to plain text mode 

    Now in the Contructor of the QWidget

    Qt Code:
    1. ....
    2.  
    3. calc = new algorithmus(this);
    To copy to clipboard, switch view to plain text mode 

    Finally I want to access the QLineEdit in the QWidget for the calculation in QThread:

    Qt Code:
    1. ....
    2.  
    3. return [U]this->parent()->inputLine.toInt()[/U] + 1000; //f.e.
    To copy to clipboard, switch view to plain text mode 

    Is this even possible?? I am a newbie

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How to access parents variables

    Ignoring completely the C++ aspect of the question, you can't access widgets from within 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. #3
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to access parents variables

    ok... and is it possbile between two QWidgtes?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: How to access parents variables

    If you use proper C++ syntax and respect scopes then yes.
    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. Replies: 2
    Last Post: 7th June 2011, 15:57
  2. Access variables of other classes
    By przemek in forum Newbie
    Replies: 8
    Last Post: 2nd August 2010, 12:32
  3. Semi-transparency through parents' widgets
    By Anatoly in forum Qt Programming
    Replies: 2
    Last Post: 21st December 2009, 10:23
  4. QStandardItemModel, parents and childs
    By alexandernst in forum Newbie
    Replies: 7
    Last Post: 23rd July 2009, 01:00
  5. QPainter and how to access the parent variables.
    By Teuniz in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2007, 15:06

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.