March 22, 2011

RSousa RSousa
Lab Rat
20 posts

Independence between dialog and application windows

 

Hello
I’m trying to include a dialog window in an application. Basically, I have a window (application window) that calls a dialog window. I´ve done that but when the dialog window is active I cannot turn application window active(push buttons for example). I only get that by closing the dialog window. What I would like to get is a totally independence between the application window and the dialog window.
Could somebody help me?

Many thanks !

Ricardo Sousa

13 replies

March 22, 2011

Andre Andre
Area 51 Engineer
6031 posts

This is dependent on the way you show your second form. Currently, it seems that you are using a modal form. You have used exec() to show it, I guess. To make it so that you can interact with both windows after showing, you need to make sure you do not create a modal window. You can do that by using show() and making sure that modal() is still false (it is by default).

 Signature 

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

March 22, 2011

Volker Volker
Robot Herder
5428 posts

Call show() instead of exec() on your QDialog subclass. You might also set the parent of the dialog to 0 (don’t forget to manually delete the dialog then, as it’s not deleted automatically be Qt in this case). See QDialog’s docs on Modeless Dialogs [doc.qt.nokia.com] for further details.

March 22, 2011

Tobias Hunger Tobias Hunger
Mad Scientist
3155 posts

http://doc.qt.nokia.com/latest/qdialog.html has lots of information about dialogs in Qt. The section on modal dialogs is of special interest to you.

March 23, 2011

RSousa RSousa
Lab Rat
20 posts

Hi,

Thank you for your answers.:)

In fact, I was using exec(). :)
The dialog window is non-modal.
I’ve changed to show() but the dialog window opens and suddenly closes…
I’m calling this dialog window from a menu.

Could you help me.

Many thanks!

All the best

Ricardo Sousa

March 23, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Please show us the code where you show your dialog.
I’m sure, it’s pretty easy.
Perhaps, the dialog is creatot on the stack and not by new?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 23, 2011

Andre Andre
Area 51 Engineer
6031 posts

If it suddenly closes, perhaps you are creating your item on the stack instead of on the heap?

 Signature 

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

March 23, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts
Andre wrote:
If it suddenly closes, perhaps you are creating your item on the stack instead of on the heap?

That’s exactly my thought

 Signature 

o_o Sorry for my rusted english.

March 25, 2011

RSousa RSousa
Lab Rat
20 posts

This is the code….

  1. //---
  2. connect(ui->actionSpectrogram,SIGNAL(toggled(bool)),this,SLOT(VerMenuSpectrogram()));
  3.  
  4. //------
  5. void MainWindow::VerMenuSpectrogram(){
  6.  
  7. Ui_Spectrogram *ui_Spect;
  8. ui_Spect= new Ui_Spectrogram();
  9. ui_Spect->setupUi(&D);
  10. D.show();
  11.  
  12. }

I really thank you!

Ricardo Sousa

Edit: Fixed code layout. Please use the @ tags; Andre

March 25, 2011

Andre Andre
Area 51 Engineer
6031 posts

My diagnoses was correct. You are creating your dialog on the stack instead of on the heap.

 Signature 

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

March 25, 2011

RSousa RSousa
Lab Rat
20 posts

How do you know that…?:)

March 25, 2011

Andre Andre
Area 51 Engineer
6031 posts
RSousa wrote:
How do you know that…?:)

I read the piece of code you posted, of course :-)

Look at line 10 of the snippet you just posted. What happens there? You create a variable called D on the stack. What happens once your code reaches line 13? That variable goes out of scope, and gets removed from the stack again. C++, the nice language it is, thoughtfully calls the destructor for the class in question for you (QDialog). Boom! Your dialog is gone again.

 Signature 

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

March 25, 2011

Volker Volker
Robot Herder
5428 posts

Because he knows the difference between stack and heap allocation. You obviously do not, so time to get some good C++ introduction and learn the basics.

Some keywords for google:

  • stack allocation
  • heap allocation
  • scope of variable

March 25, 2011

RSousa RSousa
Lab Rat
20 posts

Now I can see…. it works now…. I’m embarassed …. :)

I need vacations…..

I really thank you for all!

All the best!!!

Ricardo Sousa

 
  ‹‹ find object by name      Custom Open/Save Dialogs ››

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