2010-05-16 183 views
1

荫在QT一个绝对的初学者..如何创建关闭主窗口时打开的窗口?

我试图创建只具有文本和一个按钮,当你按下它,你会得到具有独立的程序菜单中的另一个窗口的窗口..

但不幸的是,我不知道如何创建新窗口并将其与主窗口连接起来!

所以,我需要帮助您

回答

1

这里是做到这些(你将不得不虽然修改新窗口)的main.cpp样本。

#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

非常感谢.. – Abeer 2010-05-16 22:59:39