PDA

View Full Version : Call MainWindow through QDialog



sousadaniel7
1st May 2012, 15:30
Hi.

Some say I know how do I show a MainWindow starting from a QDialog?


Regards,
Daniel Sousa

Spitfire
1st May 2012, 16:02
If you know then please share :)

If you don't know, please elaborate what you mean.

sousadaniel7
1st May 2012, 16:09
If you know then please share :)

If you don't know, please elaborate what you mean.

Sorry but I can not write very well English.

I want to know how a call MainWindow when I click a button on a QDialog.

regards,
Daniel Sousa

Spitfire
1st May 2012, 17:28
Do you have both dialog and main window and you just want to show main window over the dialog?

Is the main window hidden?
Do you want to create main window on button press?
Is the dialog modal?

Od maybe you want to call a method in main window class when some button in the dialog is pressed?

English may not be your mother tongue, but google is your friend.
Write best description you can in your language and then translate it to english using google.

From what you said I can't figure out what you need.
Sorry :/

sousadaniel7
1st May 2012, 19:15
Do you have both dialog and main window and you just want to show main window over the dialog?

Is the main window hidden?
Do you want to create main window on button press?
Is the dialog modal?

Od maybe you want to call a method in main window class when some button in the dialog is pressed?

English may not be your mother tongue, but google is your friend.
Write best description you can in your language and then translate it to english using google.

From what you said I can't figure out what you need.
Sorry :/

I want to start the application and opens a QDialog, after I click a button create a MainWindow.

Spitfire
2nd May 2012, 09:53
If you can write main window, you should be able to write code below:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

MagicDialog d( this );
if( d.exec() )
{
MainWindow w;
w.show();
return a.exec();
}
return -1;
}

In MagicDialog connect whatever button you want to accept() slot to show main window, connect other button to reject() to terminate the application.

sousadaniel7
2nd May 2012, 11:25
If you can write main window, you should be able to write code below:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

MagicDialog d( this );
if( d.exec() )
{
MainWindow w;
w.show();
return a.exec();
}
return -1;
}

In MagicDialog connect whatever button you want to accept() slot to show main window, connect other button to reject() to terminate the application.

I tried the code and you said to me the following error:

/ Users/danielsousa/Qt/Interface2-build/../Interface2/main.cpp: 8: error: invalid use of 'this' in non-member function

Spitfire
2nd May 2012, 14:49
D-oh, no need for parent there, just remove it.
Should be obvious.

sousadaniel7
2nd May 2012, 15:00
D-oh, no need for parent there, just remove it.
Should be obvious.

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

Inicio d();
if(d.exec()){


MainWindow w;
w.show();

return a.exec();
}
//Inicio w;
//w.show();
return -1;
}

I like the code on top and me the error: /Users/danielsousa/Qt/Interface2-build/../Interface2/main.cpp:10: error: request for member 'exec' in 'd', which is of non-class type 'Inicio ()()'

Spitfire
2nd May 2012, 15:24
So, why you're talking about dialog when you're not using a dialog?
Is your 'dialog' a QWidget?

Use QDialog as a base class.

And read the docummentation for QDialog.

sousadaniel7
2nd May 2012, 15:30
So, why you're talking about dialog when you're not using a dialog?
Is your 'dialog' a QWidget?

Use QDialog as a base class.

And read the docummentation for QDialog.

But I'm using a QDialog. I want to click a button that a QDialog and open a MainWindow

Spitfire
2nd May 2012, 15:37
My bad, need to read the error to the end next time :)
Drop the () from Inicio.


Inicio d;
if(d.exec())
...


and use [CODE] tags.

sousadaniel7
2nd May 2012, 16:27
My bad, need to read the error to the end next time :)
Drop the () from Inicio.


Inicio d;
if(d.exec())
...


and use [CODE] tags.

This works, but now I when I click a button from QDialog closes the application.
And instead of closing the application you want to open the MainWindow.

How do I make it?

Spitfire
2nd May 2012, 16:35
In MagicDialog connect whatever button you want to accept() slot to show main window, connect other button to reject() to terminate the application.
PS. I did not know that quote doesn't count towrads message length :>

Edit: ok, in case you don't know:


// dialog constructor or wherever you create the buttons
connect( button_closing_dialog, SIGNAL( clicked() ), this, SLOT( reject() ) );
connect( button_showin_app, SIGNAL( clicked() ), this, SLOT( accpet() ) ) ;