Hello,
I have only just started programming both C++ and Qt and have a question about accessing functions in classes.
I have a main function with a MDI and have a widget i created for the documents to open. I also have a Wizard called newWizard which currently opens shows some labels and is supposed to create a default child object in the Mdi.
the MainWindow code used to create the Mdi and the children is shown below,
#include <QtGui>
#include "mainwindow.h"
#include "newwizard.h"
#include "groupbox.h"
MainWindow::MainWindow()
{
mdiArea = new QMdiArea;
mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setViewMode(QMdiArea::TabbedView);
setCentralWidget(mdiArea);
createActions();
createMenu();
createToolbars();
readSetting();
setWindowIcon
(QIcon(":images/images/cegu.ico"));
//setCurrentFile("");
createchild();
}
void MainWindow::createchild()
{
GroupBox *child = new GroupBox;
mdiArea->addSubWindow(child);
child->show();
}
void MainWindow::fileNew()
{
newWizard wizard;
wizard.exec();
}
#include <QtGui>
#include "mainwindow.h"
#include "newwizard.h"
#include "groupbox.h"
MainWindow::MainWindow()
{
mdiArea = new QMdiArea;
mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setViewMode(QMdiArea::TabbedView);
setCentralWidget(mdiArea);
createActions();
createMenu();
createToolbars();
readSetting();
setWindowIcon(QIcon(":images/images/cegu.ico"));
//setCurrentFile("");
createchild();
}
void MainWindow::createchild()
{
GroupBox *child = new GroupBox;
mdiArea->addSubWindow(child);
child->show();
}
void MainWindow::fileNew()
{
newWizard wizard;
wizard.exec();
}
To copy to clipboard, switch view to plain text mode
the headerfile for mainwindow is shown below:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QMdiArea;
class newWizard;
{
Q_OBJECT
public:
MainWindow();
void createchild();
...
private:
void createActions();
void createMenu();
void createToolbars();
void readSetting();
void writeSetting();
void loadFile
(const QString &fileName
);
bool saveFile
(const QString &fileName
);
void setCurrentFile
(const QString &fileName
);
QMdiArea *mdiArea;
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QAction;
class QLabel;
class QMdiArea;
class newWizard;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
void createchild();
...
private:
void createActions();
void createMenu();
void createToolbars();
void readSetting();
void writeSetting();
void loadFile(const QString &fileName);
bool saveFile(const QString &fileName);
void setCurrentFile(const QString &fileName);
QString strippedName(const QString &fullFileName);
QStringList recentFiles;
QMdiArea *mdiArea;
To copy to clipboard, switch view to plain text mode
The newWizard code is shown below
#include <QtGui>
#include "newwizard.h"
#include "mainwindow.h"
newWizard
::newWizard(QWidget *parent
) : QWizard(parent)
{
addPage(new introPage);
addPage(new fileTypePage);
addPage(new whichVariablesPage);
addPage(new conclusionPage);
setWindowTitle(tr("New File Wizard"));
}
{
parent->
createchild();
}
introPage
::introPage(QWidget *parent
) : QWizardPage
(parent
){
setTitle(tr("Introduction"));
label
= new QLabel(tr
("This wizard will create a new" "File either header or Footer"
"with the variable you choose"
));
label->setWordWrap(true);
layout->addWidget(label);
setLayout(layout);
}
fileTypePage
::fileTypePage(QWidget *parent
) : QWizardPage
(parent
){
setTitle(tr("File Type Selection"));
setSubTitle(tr("Specify which File type either"
"header or footer and the name."));
connect(headerRadioButton, SIGNAL(toggled(bool)), headerNameLineEdit, SLOT(setEnabled(bool)));
headerRadioButton->setChecked(true);
connect(footerRadioButton, SIGNAL(toggled(bool)), footerNameLineEdit, SLOT(setEnabled(bool)));
footerRadioButton->setChecked(false);
footerNameLineEdit->setEnabled(false);
registerField("HeaderName", headerNameLineEdit);
registerField("headerSelect", headerRadioButton);
registerField("FooterName", footerNameLineEdit);
registerField("footerSelect", footerRadioButton);
layout->addWidget(headerRadioButton);
layout->addWidget(headerNameLineEdit);
layout->addWidget(footerRadioButton);
layout->addWidget(footerNameLineEdit);
setLayout(layout);
}
whichVariablesPage
::whichVariablesPage(QWidget *parent
) : QWizardPage
(parent
){
setTitle(tr("Variables Selection"));
setSubTitle(tr("Specify which Variables you would like to include."));
}
conclusionPage
::conclusionPage(QWidget *parent
) :QWizardPage
(parent
){
}
#include <QtGui>
#include "newwizard.h"
#include "mainwindow.h"
newWizard::newWizard(QWidget *parent) :
QWizard(parent)
{
addPage(new introPage);
addPage(new fileTypePage);
addPage(new whichVariablesPage);
addPage(new conclusionPage);
setWindowTitle(tr("New File Wizard"));
}
void newWizard::accept(QWidget *parent) : QMainWindow(parent)
{
parent->
createchild();
}
introPage::introPage(QWidget *parent) : QWizardPage(parent)
{
setTitle(tr("Introduction"));
label = new QLabel(tr("This wizard will create a new"
"File either header or Footer"
"with the variable you choose"
));
label->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
setLayout(layout);
}
fileTypePage::fileTypePage(QWidget *parent) : QWizardPage(parent)
{
setTitle(tr("File Type Selection"));
setSubTitle(tr("Specify which File type either"
"header or footer and the name."));
headerRadioButton = new QRadioButton(tr("&Header File: "));
headerNameLineEdit = new QLineEdit;
connect(headerRadioButton, SIGNAL(toggled(bool)), headerNameLineEdit, SLOT(setEnabled(bool)));
headerRadioButton->setChecked(true);
footerRadioButton = new QRadioButton(tr("&Footer File: "));
footerNameLineEdit = new QLineEdit;
connect(footerRadioButton, SIGNAL(toggled(bool)), footerNameLineEdit, SLOT(setEnabled(bool)));
footerRadioButton->setChecked(false);
footerNameLineEdit->setEnabled(false);
registerField("HeaderName", headerNameLineEdit);
registerField("headerSelect", headerRadioButton);
registerField("FooterName", footerNameLineEdit);
registerField("footerSelect", footerRadioButton);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(headerRadioButton);
layout->addWidget(headerNameLineEdit);
layout->addWidget(footerRadioButton);
layout->addWidget(footerNameLineEdit);
setLayout(layout);
}
whichVariablesPage::whichVariablesPage(QWidget *parent) : QWizardPage(parent)
{
setTitle(tr("Variables Selection"));
setSubTitle(tr("Specify which Variables you would like to include."));
}
conclusionPage::conclusionPage(QWidget *parent) :QWizardPage(parent)
{
}
To copy to clipboard, switch view to plain text mode
and the header file for that is
#ifndef NEWWIZARD_H
#define NEWWIZARD_H
#include <QWizard>
QT_BEGIN_NAMESPACE
class QMdiArea;
QT_END_NAMESPACE
class newWizard : public QWizard
{
Q_OBJECT
public:
void accept();
};
class introPage : public QWizardPage
{
Q_OBJECT
public:
private:
};
class fileTypePage : public QWizardPage
{
Q_OBJECT
public:
private:
};
class whichVariablesPage : public QWizardPage
{
Q_OBJECT
public:
whichVariablesPage
(QWidget *parent
= 0);
private:
};
class conclusionPage : public QWizardPage
{
Q_OBJECT
public:
conclusionPage
(QWidget *parent
= 0);
private:
};
#endif // NEWWIZARD_H
#ifndef NEWWIZARD_H
#define NEWWIZARD_H
#include <QWizard>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QRadioButton;
class QMdiArea;
QT_END_NAMESPACE
class newWizard : public QWizard
{
Q_OBJECT
public:
newWizard(QWidget *parent = 0);
void accept();
};
class introPage : public QWizardPage
{
Q_OBJECT
public:
introPage(QWidget *parent = 0);
private:
QLabel *label;
};
class fileTypePage : public QWizardPage
{
Q_OBJECT
public:
fileTypePage(QWidget *parent = 0);
private:
QLabel *headerNameLabel;
QLabel *footerNameLabel;
QLineEdit *headerNameLineEdit;
QLineEdit *footerNameLineEdit;
QRadioButton *headerRadioButton;
QRadioButton *footerRadioButton;
};
class whichVariablesPage : public QWizardPage
{
Q_OBJECT
public:
whichVariablesPage(QWidget *parent = 0);
private:
QLabel *label;
};
class conclusionPage : public QWizardPage
{
Q_OBJECT
public:
conclusionPage(QWidget *parent = 0);
private:
QLabel *label;
};
#endif // NEWWIZARD_H
To copy to clipboard, switch view to plain text mode
This code is not the finished article and is still a work in progress. As can be seen in the newWizard code at lines 18 to 23 i am trying to access the createchild() function from the mainwindow in that function when the wizard closes.
Any help on this would be great.
Thanks
James Parsons
Bookmarks