Results 1 to 20 of 23

Thread: How to access the UI from another class ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Oct 2009
    Posts
    38
    Platforms
    Unix/X11 Windows
    Thanks
    13

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

    robotShooter.cpp :

    Qt Code:
    1. class koala
    2. {
    3.  
    4. public:
    5. void log1(){
    6. robotShooter* another_object = new robotShooter();
    7. another_object->LOG("text");
    8. }
    9.  
    10. };
    11.  
    12. void robotShooter::LOG(QString text){
    13. ui->LOG->append(text);
    14. }
    15.  
    16. robotShooter::robotShooter(QWidget *parent)
    17. : QMainWindow(parent), ui(new Ui::robotShooter)
    18. {
    19. ui->setupUi(this);
    20.  
    21. koala *KO = new koala();
    22. KO->log1();
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 


    robotShooter.h

    Qt Code:
    1. #ifndef ROBOTSHOOTER_H
    2. #define ROBOTSHOOTER_H
    3.  
    4. #include <QtGui/QMainWindow>
    5.  
    6. namespace Ui
    7. {
    8. class robotShooter;
    9. }
    10.  
    11. class robotShooter : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. robotShooter(QWidget *parent = 0);
    17. ~robotShooter();
    18.  
    19. void LOG(QString);
    20.  
    21. //private:
    22. Ui::robotShooter *ui;
    23. };
    24.  
    25. #endif // ROBOTSHOOTER_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by fitzy; 26th October 2009 at 16:25.

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.