tags:

views:

119

answers:

2

I had designed some gui through Qt cretor on linux,these design consists of some fields, text edit , & some push buttons . Now my doubt is when i press on push button i want display aanother window . Is there any GUI option for this or any hard code.please let me know if any hard code............. waiting for answer

Tanks in advance. Ram

A: 

on click event of button you create another widget and show. another option is Stacked widget, http://doc.trolltech.com/4.6/qstackedwidget.html

Shadow
+2  A: 

You need signals and slots.

You have to connect the clicked signal to a custom slot, created by you, of your main widget.

Corrected Code, based in the comments of Patrice Bernassola and Job.

In the class definition (.h file) add the lines:

Q_OBJECT

private slots:
    void exampleButtonClicked();
private:
    QDialog *exampleDialog;

The macro Q_OBJECT is needed when you define signals or slots in your classes.

The variable exampleDialog should be declared in the definition file to have access to it in the slot.

And you have to initialize it, this is commonly done in the constructor

ExampleClass::ExampleClass()
{
    //Setup you UI
    dialog = new QDialog;
}

In the class implementation (.cpp file) add the code that does what you want, in this case create a new window.

void ExampleClass::exampleButtonClicked()
{
    exampleDialog->show();
}

And also you have to connect the signal to the slot with the line:

connect(exampleButton, SIGNAL(clicked()), this, SLOT(exampleButtonClicked()));

Your question is somehwat basic, so I suggest to read a basic tutorial, in this way you can make progress faster, avoiding waiting for answers. Some links to tutorials that were useful to me:

http://zetcode.com/tutorials/qt4tutorial/

http://doc.qt.nokia.com/latest/tutorials-addressbook.html

Hope it helps!

Mkfnx
In your example, the new dialog will be shown and immediately destructed since the exampleDialog will go out of scope at the end of the function. Make your dialog modal or use a member variable to allow dialog to live out of this function.
Patrice Bernassola
Or just use QDialog::exec()
Job
Thanks for the correction. Also forgot the Q_OBJECT macro.It's Already corrected.
Mkfnx