Results 1 to 7 of 7

Thread: How to get a reference for a control of the main form?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to get a reference for a control of the main form?

    Using the QT Designer I have made the following things:
    1-a main form called MainFormDlg (QMainWindow) with a Tree Widget control (treeDownloads);
    2-a dialog box called DownloadDlg (QDialog) containing OK and CANCEL buttons.

    When the user presses the OK button in the DownloadDlg dialog, I wanna clear the content of the treeDownloads. But I don't know how to get a reference to treeDownloads which is from the main form.

    My code below compiles fine, but when I press the OK button on the DownloadDlg dialog, the program simply crashes. (Please, look at my questions at the commented lines **):

    //downloaddlg.cpp:
    Qt Code:
    1. #include "downloaddlg.h"
    2.  
    3. DownloadDlg::DownloadDlg(QWidget *parent) :
    4. QDialog(parent){
    5. setupUi(this);
    6.  
    7. connect(buttonBox, SIGNAL(accepted()), this, SLOT(addUrlsToTree()));
    8.  
    9. setAttribute(Qt::WA_DeleteOnClose);
    10. pMainForm = (Ui_MainFormDlg*)parent; // ** Is this correct? **
    11. }
    12.  
    13. void DownloadDlg::addUrlsToTree(){
    14. pMainForm->treeDownloads->clear(); // ** Is this correct? **
    15. }
    To copy to clipboard, switch view to plain text mode 

    //downloaddlg.h:
    Qt Code:
    1. #ifndef DOWNLOADDLG_H
    2. #define DOWNLOADDLG_H
    3.  
    4. #include <QtGui/QDialog>
    5. #include <QtGui/QMainWindow>
    6. #include "ui_downloaddlg.h"
    7. #include "ui_mainform.h"
    8. //#include "mainform.h"
    9.  
    10. class DownloadDlg : public QDialog, private Ui::DownloadDlg {
    11. Q_OBJECT
    12. Q_DISABLE_COPY(DownloadDlg)
    13. public:
    14. explicit DownloadDlg(QWidget *parent = 0);
    15.  
    16. private:
    17. Ui_MainFormDlg *pMainForm;
    18.  
    19. private slots:
    20. void addUrlsToTree();
    21.  
    22. protected:
    23. virtual void changeEvent(QEvent *e);
    24. };
    25.  
    26. #endif // DOWNLOADDLG_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by thiforums; 20th March 2009 at 04:16.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  3. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 13:41
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15

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.