Results 1 to 20 of 23

Thread: How to access the UI from another class ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: How to access the UI from another class ?

    Qt Code:
    1. class CA {
    2. public:
    3. void log (QString *str);
    4. };
    5.  
    6. class CB {
    7. public:
    8. void log (QString *str);
    9. };
    10.  
    11. CA firstclass;
    12. CB secondclass;
    13.  
    14. void CA::log(QString *str) {
    15. secondclass.log("foo");
    16. }
    17.  
    18. void CB::log(QString *str) {
    19. ui->LOG->append(str);
    20. }
    To copy to clipboard, switch view to plain text mode 

    You can also have firstclass and secondclass as pointers by using new to initialise them and use -> instead of '.'
    Last edited by squidge; 26th October 2009 at 20:28.

  2. The following user says thank you to squidge for this useful post:

    fitzy (26th October 2009)

  3. #2
    Join Date
    Oct 2009
    Posts
    38
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How to access the UI from another class ?

    I don't get it.

    I have pasted your example (by the way, I think you meant CA::log(QString *str) not A::log(QString *str) ) but it doesn't work.

    There are many errors :

    Qt Code:
    1. ISO C++ forbids declaration of `log' with no type
    2. CA::log(QString*)' does not match any in class `CA'
    3. ISO C++ forbids declaration of `log' with no type
    4. etc
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. cannot access QLineEdit text in other methods of the class...
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 29th September 2009, 12:07
  2. Problem with QDialog class
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 09:03
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. Replies: 4
    Last Post: 26th June 2007, 19:19
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

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
  •  
Qt is a trademark of The Qt Company.