I am trying to lear QT creator and have searched and read the forum and several areas but I must be missing something. But first I have a question. I am writing a program that will have a main window and then widgets (dialog forms) that I want to display in the main window. I read about stacked widgets but am concerned that if all the widgets are loaded then this could create a resource issue. Is that thought process correct? I am able to create the forms and have the button open the second form. The problem is that the form does not open as a child of the main window. I am using QT Creator 1.2.1 based on QT 4.5.2. What am I missing? Here is the code!
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
protected:
private:
Ui::MainWindow *ui;
private slots:
void on_btnNextPage_clicked();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
private slots:
void on_btnNextPage_clicked();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "page2.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_btnNextPage_clicked()
{
Page2* page2 = new Page2 () ;
page2->exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "page2.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_btnNextPage_clicked()
{
Page2* page2 = new Page2 () ;
page2->exec();
}
To copy to clipboard, switch view to plain text mode
page2.h
#ifndef PAGE2_H
#define PAGE2_H
#include <QDialog>
namespace Ui {
class Page2;
}
{
Q_OBJECT
public:
explicit Page2
(QWidget *parent
= 0);
~Page2();
protected:
private:
Ui::Page2 *ui;
};
#endif // PAGE2_H
#ifndef PAGE2_H
#define PAGE2_H
#include <QDialog>
namespace Ui {
class Page2;
}
class Page2 : public QDialog
{
Q_OBJECT
public:
explicit Page2(QWidget *parent = 0);
~Page2();
protected:
void changeEvent(QEvent *e);
private:
Ui::Page2 *ui;
};
#endif // PAGE2_H
To copy to clipboard, switch view to plain text mode
page2.cpp
#include "page2.h"
#include "ui_page2.h"
ui(new Ui::Page2)
{
ui->setupUi(this);
}
Page2::~Page2()
{
delete ui;
}
void Page2
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
#include "page2.h"
#include "ui_page2.h"
Page2::Page2(QWidget *parent) :
QDialog(parent),
ui(new Ui::Page2)
{
ui->setupUi(this);
}
Page2::~Page2()
{
delete ui;
}
void Page2::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
Thanks for your assistance
Rick
Bookmarks