开发者

how to create window that opened when close main window?

开发者 https://www.devze.com 2022-12-30 05:19 出处:网络
开发者_如何学JAVAIam a absolute Beginner in QT.. i am trying to create window that has only text and one push button when you press it, you will get another window that has menu for program ..
开发者_如何学JAVA

Iam a absolute Beginner in QT..

i am trying to create window that has only text and one push button when you press it, you will get another window that has menu for program ..

but Unfortunately, i didn't know how can i create new window and connect it with main window!

so, i need to helping you


Here is a sample of main.cpp that do exactly that (you will have to modify the new window though).

#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

精彩评论

暂无评论...
验证码 换一张
取 消