2010-05-16 7 views
1

Iam Un débutant absolu QT ..comment créer une fenêtre qui a ouvert lorsque fermer la fenêtre principale?

je suis en train de créer une fenêtre qui ne dispose que du texte et un bouton lorsque vous appuyez dessus, vous obtiendrez une autre fenêtre qui propose un menu pour le programme ..

mais Malheureusement, je ne savais pas comment puis-je créer une nouvelle fenêtre et le connecter avec la fenêtre principale!

donc, je dois vous aider

Répondre

1

Voici un échantillon de main.cpp qui font exactement ce que (vous devrez modifier la nouvelle fenêtre bien).

#include <QtGui> 

int main(int argc, char* argv[]) { 
    QApplication app(argc, argv); 

    QWidget *firstWindow = new QWidget(); 
    QLabel *text = new QLabel("Here is some text one the first window."); 
    QPushButton *button = new QPushButton("Button on the first window that display the other window"); 
    QBoxLayout *layout = new QVBoxLayout(); 
    layout->addWidget(text); 
    layout->addWidget(button); 
    firstWindow->setLayout(layout); 

    QWidget *secondWindow = new QWidget(); 
    // add some things on the second window 

    // on button click, close the first window and show the second one 
    connect(button, SIGNAL(clicked(bool)), secondWindow, SLOT(show())); 
    connect(button, SIGNAL(clicked(bool)), firstWindow, SLOT(close())); 

    // display the first window at the start of the application. 
    firstWindow->show(); 

    return app.exec(); 
} 
+0

merci beaucoup .. – Abeer

Questions connexes