Results 1 to 8 of 8

Thread: Accessing the UI ! Help !

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Accessing the UI ! Help !

    Quote Originally Posted by fitzy View Post
    Qt Code:
    1. guiClass ::guiClass (QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::guiClass )
    3. {
    4. ui->setupUi(this);
    5.  
    6.  
    7. //this->ui->progressBar->setValue(80); // IT WORKS, but it is in guiClass
    8.  
    9. anotherClass *anotherclass = new anotherClass(this);
    10. anotherclass->anything();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    I knew it! you haven't set the pointer guiClass in anotherClass. So you accessing a null pointer!

    Qt Code:
    1. class anotherClass : public QProgressBar {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. anotherClass(QObject* parent);
    7. void anything();
    8. guiClass *guiClass;
    9. void setBackPointer(guiClass *p) {guiClass = p;} // <- add
    10.  
    11. };
    12.  
    13. // and then
    14.  
    15. guiClass ::guiClass (QWidget *parent)
    16. : QMainWindow(parent), ui(new Ui::guiClass )
    17. {
    18. ui->setupUi(this);
    19. anotherClass *anotherclass = new anotherClass(this);
    20. anotherclass->setBackPointer(this); // <- add
    21. anotherclass->anything();
    22. }
    To copy to clipboard, switch view to plain text mode 

    you can also use the parent of your constructor for setting the back pointer, but you really should learn signal and sots...

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

    fitzy (29th November 2009)

Similar Threads

  1. QTableView : accessing the data
    By marvaneke in forum Newbie
    Replies: 10
    Last Post: 30th March 2012, 11:31
  2. QCachece accessing problem
    By rajini333 in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2009, 19:15
  3. Accessing deleted memory, Producer Consumer app
    By ^NyAw^ in forum General Programming
    Replies: 3
    Last Post: 2nd August 2008, 13:58
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 10:20
  5. Accessing Environment Variables
    By mhoover in forum Qt Programming
    Replies: 6
    Last Post: 21st September 2006, 15:05

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.