[SOLVED] QmainWinows : opening trouble SubWindow
-
Hi everybody !
I'm trying to understand QMainWindow and QMDiArea how is operate, but i've an trouble :
I have one main window with inside "Fenetre1", when we cliclked on button(DockWidget) is opening a second window"fenetre2" wich have a button for opening third window"fenetre3".
The button on second window doesn't operate but the button on menu "affichage->MDI 3" is operate(window 3 is open).
I would like to know what is my problem !
thanks for your comment and your help.
Richard.
P.S. : When i transform third window on classic QDialog(out of main window, not in subwindow) my button on second window operate, i'm little bit surprised !
main_window.cpp
@#include "main_window.h"
#include "window1.h"main_window::main_window()
{
//Définition de la fenêtre
centralzone = new QMdiArea;
setWindowTitle("QMainWindow Test");
setFixedSize(600,300);
setCentralWidget(centralzone);//Définition barre menu
QMenu *m_fichier = menuBar()->addMenu("Fichier");
QAction *Quitter = new QAction ("Quitter",this);
m_fichier->addAction(Quitter);
connect(Quitter,SIGNAL(triggered()),qApp,SLOT(quit()));QMenu *m_affichage =menuBar()->addMenu("Affichage"); QAction *mdi2 = new QAction("mdi 2",this); mdi3 = new QAction("mdi 3",this); m_affichage->addAction(mdi2); m_affichage->addAction(mdi3); connect(mdi2,SIGNAL(triggered()),this,SLOT(mdi_2())); connect(mdi3,SIGNAL(triggered()),this,SLOT(mdi_3()));
//Paramètre fenêtre 1
ZT1 = new QDialog;
win1 = new QMdiSubWindow;
win1 = centralzone->addSubWindow(ZT1);
win1->setWindowTitle("MDI 1");
win1->resize(200,110);
lEdit = new QLineEdit("Test");QFormLayout *f_layout = new QFormLayout; f_layout->addWidget(lEdit); ZT1->setLayout(f_layout);
//DockWidget
QDockWidget *dockW = new QDockWidget("DockWidget");
QPushButton *bouton1 = new QPushButton("Essai");
connect(bouton1,SIGNAL(released()),this,SLOT(mdi_2()));
dockW->setWidget(bouton1);
addDockWidget(Qt::BottomDockWidgetArea,dockW);
}void main_window::mdi_2()
{
//Définition de la fenêtre 2
window1 *w2 = new window1(lEdit->text());
win2 = new QMdiSubWindow;
win2 = centralzone->addSubWindow(w2);
win2->setWindowTitle("MDI 2");
win2->resize(200,110);
win2->show();
}
void main_window::mdi_3()
{
//Définition de la fenêtre 3
QLabel lbl3 = new QLabel("MDI 3");
win3 = new QMdiSubWindow;
win3 = centralzone->addSubWindow(lbl3);
win3->setWindowTitle("MDI 3");
win3->resize(200,110);
win3->show();
}
/ QDialog *dial_mdi3 = new QDialog;
dial_mdi3->setWindowTitle("MDI 3");
QLabel *lbl3 = new QLabel("MDI 3");
QVBoxLayout v_layout = new QVBoxLayout;
v_layout->addWidget(lbl3);
dial_mdi3->setLayout(v_layout);
dial_mdi3->show();/
@main_window.h
@#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H#include <QAction>
#include <QApplication>
#include <QBoxLayout>
#include <QDialog>
#include <QDockWidget>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QMenu>
#include <QMenuBar>
#include <QPushButton>
#include <QSize>
#include <QString>
#include <QTextEdit>
#include <QWidget>#include "window1.h"
class main_window : public QMainWindow
{
Q_OBJECT
public:
main_window();private:
QLineEdit *lEdit;
QMdiArea *centralzone;
QMdiSubWindow *win1, *win2, *win3;
QDialog *ZT1, *ZT2;QAction *mdi3;
public slots:
void mdi_2();
void mdi_3();
};
#endif // MAIN_WINDOW_H
@window.cpp
@#include "window1.h"
#include "main_window.h"window1::window1(QString str) : QDialog()
{
QLabel *lbl = new QLabel("str");
lbl->setText(str);
main_window *m_win = new main_window;QPushButton *bouton =new QPushButton("MDI 3"); connect(bouton,SIGNAL(clicked()),m_win,SLOT(mdi_3())); QVBoxLayout *v_layout = new QVBoxLayout; v_layout->addWidget(lbl); v_layout->addWidget(bouton); setLayout(v_layout);
}
@window.h
@#ifndef WINDOW1_H
#define WINDOW1_H#include "main_window.h"
class window1 : public QDialog
{
public:
window1(QString str);
};
#endif // WINDOW1_H
@have a nice day !
-
any body have an idea ?
-
Problem solved !
implementation error of class !