Results 1 to 4 of 4

Thread: how to access the Member Variable of MainWindow from another class?

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Question how to access the Member Variable of MainWindow from another class?

    Hi Friends,

    i am facing the following problem...

    how i can access the variable which is declared in the mainwindow class from some other class?


    code snippet:

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8. public:
    9. QList<int> cno_airfoilgeom;
    10. QList<int> sno_airfoilgeom;
    11.  
    12. };
    13.  
    14. class AirfoilGeomTab : public QWidget
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. AirfoilGeomTab(QWidget *parent = 0);
    20.  
    21. };
    22.  
    23. i wanted to use the "cno_airfoilgeom" variable in the "AirfoilGeomTab" constructor...
    24.  
    25. AirfoilGeomTab::AirfoilGeomTab(QWidget *parent)
    26. : QWidget(parent)
    27. {
    28.  
    29. // i wanted to use the "cno_airfoilgeom" variable here
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 
    can anyone please help me...?

    Thanks in Advance,
    mammaiap
    Last edited by high_flyer; 12th April 2011 at 12:46. Reason: code tags

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to access the Member Variable of MainWindow from another class?

    This is basics of C++ and object oriented programing! Provide MainWindow method which will expose this field in safe way.

  3. #3
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to access the Member Variable of MainWindow from another class?

    what relation between AirfoilGeomTab and MainWindow, parent is MainWindow in AirfoilGeomTab's constructor?
    And i think you'd better write set get function

  4. #4
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: how to access the Member Variable of MainWindow from another class?

    Hi Marek,

    thanks for your immediate reply...

    but can you please explain little bit more....with some code example?

    Thanks in Advance


    Added after 10 minutes:


    Hi wong,

    here i am attaching the source files

    basically what i wanted is...

    i am reading the input file and get some values....and store it in the container...

    here(QList<int> cno_airfoilgeom) in mainwindow...

    i wanted to use this value in some other class contructor...(class AirfoilGeomTab)..


    i create a TabWidget which consist the "AirfoilGeomTab"...

    thanks,
    Attached Files Attached Files
    Last edited by mammaiap; 12th April 2011 at 10:58.

Similar Threads

  1. Replies: 4
    Last Post: 17th January 2011, 14:05
  2. Replies: 4
    Last Post: 29th May 2010, 12:56
  3. Replies: 22
    Last Post: 8th October 2008, 13:54
  4. Replies: 5
    Last Post: 14th July 2006, 22:42
  5. Std iterator as private member variable
    By Michiel in forum General Programming
    Replies: 5
    Last Post: 21st April 2006, 15:27

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.