November 17, 2011

bmps bmps
Lab Rat
6 posts

[Solved]Opening a New Form with new Widgets.

 

I have built a GUI and its working. I need to put in a page where ill put in some details of the GUI and the Licenses and End User rights for the GUI. For this i have a Push Button which when clicked should open another form where i have a Text Browser and a Link which directs to the GPL 3.0 Licenses etc. But for some reason the second form is not being called when i click on it. This is the code that i have written. Please let me know where am going wrong.
My first form where my basic GUI is created is test.ui(which has its own test.h and test.cpp). And now i have added a dialog.ui(which has a dialog.cpp and dialog.h). My pushbutton is in test.ui whiuch when called should start the dialog.ui.

  1. void unametest::on_pushbutton_clicked()
  2. {
  3.     dialog *dlg=new dialog(this);
  4.     dlg->show();
  5.     dlg->raise();
  6.     dialog->activateWindow();
  7. }

[EDIT: code formatting, please wrap in @-tags, Volker]

8 replies

November 17, 2011

fluca1978 fluca1978
Lab Rat
524 posts
bmps wrote:
  1. void unametest::on_pushbutton_clicked()
  2. {
  3.     dialog *dlg=new dialog(this);
  4.     dlg->show();
  5.     dlg->raise();
  6.     dialog->activateWindow();
  7. }

First, please use the right tag to mark your code.
Second, in your code you have pointers like dlg and dialog, I suspect this is an error rewriting your code for your post. What happens if you call exec on the dialog?

November 18, 2011

bmps bmps
Lab Rat
6 posts

How do i call the exec on the dialog?? Not able to figure it out.

November 18, 2011

rokemoon rokemoon
Lab Rat
197 posts

bmps wrote:
How do i call the exec on the dialog?? Not able to figure it out.

Here it is exec [doc.qt.nokia.com]

November 18, 2011

qxoz qxoz
Area 51 Engineer
660 posts

You can use follow:

  1. void unametest::on_pushbutton_clicked()
  2. {
  3.     dialog *dlg=new dialog(this);
  4.     dlg->exec();
  5. }

or

  1. void unametest::on_pushbutton_clicked()
  2. {
  3.     dialog *dlg=new dialog(this);
  4.     dlg->setWindowModality(Qt::WindowModal);
  5.     dlg->exec();
  6. }

if you need modal window

November 18, 2011

qxoz qxoz
Area 51 Engineer
660 posts

Sory i mean:

  1. void unametest::on_pushbutton_clicked()
  2. {
  3.     dialog *dlg=new dialog(this);
  4.     dlg->setModal(true);
  5.     dlg->exec();
  6. }

November 18, 2011

Andre Andre
Area 51 Engineer
6076 posts

Doesn’t calling exec() on a QDialog (-subclass) always result in a modal dialog? The setModel(true) call seems superfluous to me. You need to call show() if you want the dialog to pop up non-modally.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

November 18, 2011

Volker Volker
Robot Herder
5428 posts

Andre is right. exec() on a dialog always shows it application model (default) or window modal. A call to setModel is not necessary.

November 21, 2011

qxoz qxoz
Area 51 Engineer
660 posts

Thanks, I’ll remember.

 
  ‹‹ QSettings dont see all keys      Caching QIcon ››

You must log in to post a reply. Not a member yet? Register here!