Results 1 to 2 of 2

Thread: Tips for accesing components on forms from code ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Tips for accesing components on forms from code ?

    Is there any QT tutorial explaining how to access componentes from code placed into different classes ?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Tips for accesing components on forms from code ?

    1. signals and slots
    2. access functions
    ...

    Example:

    Qt Code:
    1. class A : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. A();
    7. ~A();
    8.  
    9. int something();
    10. void setSomething(int something);
    11.  
    12. signals:
    13. void somethingWasSet(int something);
    14.  
    15. public slots:
    16. void setSomethingElse(int something);
    17.  
    18. private:
    19. int theThing;
    20. };
    21.  
    22. class B : public QObject
    23. {
    24. Q_OBJECT
    25.  
    26. public:
    27. B();
    28. ~B();
    29.  
    30. int something();
    31. void setSomething(int something);
    32.  
    33. signals:
    34. void somethingWasSet(int something);
    35.  
    36. public slots:
    37. void setSomethingElse(int something);
    38.  
    39. private:
    40. int theThing;
    41. };
    42.  
    43. ...
    44.  
    45. A a;
    46. B b;
    47. connect(&a, SIGNAL(somethingWasSet(int)), &b, SLOT(setSomethingElse(int)));
    48.  
    49. ...
    50. b.setSomething(a.something());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  2. accesing events in another widget
    By andreime in forum Newbie
    Replies: 2
    Last Post: 19th July 2009, 10:02
  3. Designer Layout Tips?
    By GimpMaster in forum Newbie
    Replies: 3
    Last Post: 3rd June 2009, 21:17
  4. Need some debugging tips for Qt
    By montylee in forum Qt Programming
    Replies: 4
    Last Post: 17th March 2009, 22:05
  5. tips before building a Qt app
    By juanrb in forum Newbie
    Replies: 4
    Last Post: 24th April 2008, 20:59

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.