(First of all - read this post to the end, although it's so long :])
Try this way:
#ifndef DOWNLOADDLG_H
#define DOWNLOADDLG_H
#include <QtGui/QDialog>
#include <QtGui/QMainWindow>
#include "ui_downloaddlg.h"
#include "ui_mainform.h"
//#include "mainform.h"
class MainFormDlg; // let DownloadDlg know about MainFormDlg without includeing file here
class DownloadDlg
: public QDialog,
private Ui
::DownloadDlg { Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg(MainFormDlg*parent = 0); // change QWidget to MainFormDlg as you this would be the parent for sure
private:
MainFormDlg *pMainForm; // don use the UI_, just make one more method in MainFormDlg (see below)
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 MainFormDlg; // let DownloadDlg know about MainFormDlg without includeing file here
class DownloadDlg : public QDialog, private Ui::DownloadDlg {
Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg(MainFormDlg*parent = 0); // change QWidget to MainFormDlg as you this would be the parent for sure
private:
MainFormDlg *pMainForm; // don use the UI_, just make one more method in MainFormDlg (see below)
private slots:
void addUrlsToTree();
protected:
virtual void changeEvent(QEvent *e);
};
#endif // DOWNLOADDLG_H
To copy to clipboard, switch view to plain text mode
And then:
#include "downloaddlg.h"
#include "mainform.h" // the file with MainFormDlg
DownloadDlg::DownloadDlg(MainFormDlg*parent) :
pMainForm(parent) // pMainForm points to the parent = MainFormDlg
{
setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(addUrlsToTree()));
setAttribute(Qt::WA_DeleteOnClose);
}
void DownloadDlg::addUrlsToTree(){
// but to get to the ui parts you have make them public or make some other methods
}
#include "downloaddlg.h"
#include "mainform.h" // the file with MainFormDlg
DownloadDlg::DownloadDlg(MainFormDlg*parent) :
QDialog(parent),
pMainForm(parent) // pMainForm points to the parent = MainFormDlg
{
setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(addUrlsToTree()));
setAttribute(Qt::WA_DeleteOnClose);
}
void DownloadDlg::addUrlsToTree(){
// but to get to the ui parts you have make them public or make some other methods
}
To copy to clipboard, switch view to plain text mode
For example you can do:
public:
Ui::MainFormDlg * ui;
public:
Ui::MainFormDlg * ui;
To copy to clipboard, switch view to plain text mode
in MainFormDlg class, or make some public method like void clearTree(); which will clear the tree.
But this is the way you want to do and it's not good i think. I think the better way is to use signals and slots. I dont know what the buttonBox is in your dialog, but if the signal is emitted outside the DownloadDlg you can just connect accepted() to the clear() slot of the tree in MainFormDlg just below the DownloadDlg creation. If it's not possible to get the signal accepted() in MainFormDlg, make your own signal like acceptedSignal() and connect it to clear(). Example:
#ifndef DOWNLOADDLG_H
#define DOWNLOADDLG_H
#include <QtGui/QDialog>
#include <QtGui/QMainWindow>
#include "ui_downloaddlg.h"
#include "ui_mainform.h"
class DownloadDlg
: public QDialog,
private Ui
::DownloadDlg { Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg
(QWidget *parent
= 0);
signals:
void acceptedSignal();
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"
class DownloadDlg : public QDialog, private Ui::DownloadDlg {
Q_OBJECT
Q_DISABLE_COPY(DownloadDlg)
public:
explicit DownloadDlg(QWidget *parent = 0);
signals:
void acceptedSignal();
protected:
virtual void changeEvent(QEvent *e);
};
#endif // DOWNLOADDLG_H
To copy to clipboard, switch view to plain text mode
#include "downloaddlg.h"
DownloadDlg
::DownloadDlg(QWidget *parent
) : setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SIGNAL(acceptedSignal())); // first signal emits second one
setAttribute(Qt::WA_DeleteOnClose);
}
#include "downloaddlg.h"
DownloadDlg::DownloadDlg(QWidget *parent) :
QDialog(parent){
setupUi(this);
connect(buttonBox, SIGNAL(accepted()), this, SIGNAL(acceptedSignal())); // first signal emits second one
setAttribute(Qt::WA_DeleteOnClose);
}
To copy to clipboard, switch view to plain text mode
and in MainFormDlg:
void MainForm::newDownloadDlg(){
DownloadDlg *dlg=new DownloadDlg(this);
connect(dlg, SIGNAL(acceptedSignal()), ui->treeDownloads, SLOT(clear())); // connects accepted with clear, and that's what you want, right?
if(dlg->exec()){
//ok pressed
}
}
void MainForm::newDownloadDlg(){
DownloadDlg *dlg=new DownloadDlg(this);
connect(dlg, SIGNAL(acceptedSignal()), ui->treeDownloads, SLOT(clear())); // connects accepted with clear, and that's what you want, right?
if(dlg->exec()){
//ok pressed
}
}
To copy to clipboard, switch view to plain text mode
That is better way i think :] good luck! :]
Bookmarks