tags:

views:

43

answers:

1

Hi everyone ..

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

+1  A: 

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();
}
Lohrun
thanks a lot ..
Abeer