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:
#include "downloaddlg.h"
DownloadDlg
::DownloadDlg(QWidget *parent
) : setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(addUrlsToTree()));
setAttribute(Qt::WA_DeleteOnClose);
pMainForm = (Ui_MainFormDlg*)parent; // ** Is this correct? **
}
void DownloadDlg::addUrlsToTree(){
pMainForm->treeDownloads->clear(); // ** Is this correct? **
}
#include "downloaddlg.h"
DownloadDlg::DownloadDlg(QWidget *parent) :
QDialog(parent){
setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(addUrlsToTree()));
setAttribute(Qt::WA_DeleteOnClose);
pMainForm = (Ui_MainFormDlg*)parent; // ** Is this correct? **
}
void DownloadDlg::addUrlsToTree(){
pMainForm->treeDownloads->clear(); // ** Is this correct? **
}
To copy to clipboard, switch view to plain text mode
//downloaddlg.h:
#ifndef DOWNLOADDLG_H
#define DOWNLOADDLG_H
#include <QtGui/QDialog>
#include <QtGui/QMainWindow>
#include "ui_downloaddlg.h"
#include "ui_mainform.h"
//#include "mainform.h"
class DownloadDlg
: public QDialog,
private Ui
::DownloadDlg { Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg
(QWidget *parent
= 0);
private:
Ui_MainFormDlg *pMainForm;
private slots:
void addUrlsToTree();
protected:
virtual void changeEvent
(QEvent *e
);
};
#endif // DOWNLOADDLG_H
#ifndef DOWNLOADDLG_H
#define DOWNLOADDLG_H
#include <QtGui/QDialog>
#include <QtGui/QMainWindow>
#include "ui_downloaddlg.h"
#include "ui_mainform.h"
//#include "mainform.h"
class DownloadDlg : public QDialog, private Ui::DownloadDlg {
Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg(QWidget *parent = 0);
private:
Ui_MainFormDlg *pMainForm;
private slots:
void addUrlsToTree();
protected:
virtual void changeEvent(QEvent *e);
};
#endif // DOWNLOADDLG_H
To copy to clipboard, switch view to plain text mode
Bookmarks