#include "mainwindow.h"#include "ui_mainwindow.h"#include "caesar.h"#include <QMdiArea>#include <QMdiSubWindow>QWidget *widget;caesar *form_caesar;MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); MainWindow::setCentralWidget(ui->mdiArea);}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_action_triggered(){ form_caesar = new caesar; ui->mdiArea->addSubWindow(form_caesar); form_caesar->show();}
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>namespace Ui { class MainWindow;}[b]class caesar; // класс второй формы[/b]class MainWindow : public QMainWindow { Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); Ui::MainWindow *ui; [b]caesar* caesar_w; // как сказали сделать указатель на вторую форму[/b]protected: void changeEvent(QEvent *e);private:private slots: void on_action_triggered();};#endif // MAINWINDOW_H
#include "caesar.h"#include "ui_caesar.h"#include "mainwindow.h"caesar::caesar(QWidget *parent) : QWidget(parent), ui(new Ui::caesar){ ui->setupUi(this); QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251"));}caesar::~caesar(){ delete ui;}void caesar::changeEvent(QEvent *e){ QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; }}void caesar::on_pushButton_clicked(){ mw->setWindowTitle("12345");}
#ifndef CAESAR_H#define CAESAR_H#include <QWidget>namespace Ui { class caesar;}class MainWindow;class caesar : public QWidget { Q_OBJECTpublic: caesar(QWidget *parent = 0); ~caesar(); MainWindow* mw;protected: void changeEvent(QEvent *e);private: Ui::caesar *ui;private slots: void on_pushButton_clicked();};#endif // CAESAR_H
void caesar::on_pushButton_clicked(){ mw->setWindowTitle("12345");}
caesar::caesar(QWidget *parent) : QWidget(parent), ui(new Ui::caesar){ ui->setupUi(this); lib.load(); mw = new MainWindow; // <---- QTextCodec::setCodecForLocale(QTextCodec::codecForName("Windows-1251"));}
class MainWindow;class caesar : public QWidget { Q_OBJECTpublic: caesar(MainWindow * mainWnd, QWidget *parent = 0); ~caesar();private: MainWindow* mw;.....
caesar::caesar(MainWindow * mainWnd, QWidget *parent) : QWidget(parent), ui(new Ui::caesar){ ui->setupUi(this); mw = mainWnd;........}
void MainWindow::on_action_triggered(){ form_caesar = new caesar(this);}