I am trying to learn QT creator and have searched and read the forum and several other areas but I must be missing something. I am writing a program that will have a main window and then widgets (dialog forms) that I want to open and close inside the main window. I am able to create the forms and have a button open the second form. The problem is that the form does not open as a child of the main window. I think I might need to create some sort of container in the main form and pass a pointer to that container? I am lost at how to do this. 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(); //Identify a pointer here? Buy how?
};
#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(); //Identify a pointer here? Buy how?
};
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* page2 = new Page2 (this) ; ??
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* page2 = new Page2 (this) ; ??
page2->exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks