PDA

View Full Version : Show parent window



Qt Coder
5th June 2009, 12:12
Hello All,


I have developed one application,in which I m using 4-5 different screens to navigate.

Now from Mainwindow screen I have activated the another screen,so my mainwindow is now hidden .But in this new screen on one button click event I need to show the mainwindow screen .

How to acheive it???

The code I m using is as follows

in MainWindow.cpp



void MainWindow::f_Open_screen_al()
{
screen_al->show();
screen_al->activateWindow();
}

void MainWindow::ShowMainWindow()
{
this->activateWindow();
}



and in screen_al.cpp


connect(ui.pushbutton, SIGNAL(clicked()), this->parent(), SLOT(ShowMainWindow()));



But No mainwindow is displayed.....

Pls help

spirit
5th June 2009, 12:26
try this


void MainWindow::ShowMainWindow()
{
raise();
this->activateWindow();
}

Qt Coder
5th June 2009, 12:41
I tried this code


void MainWindow::ShowMainWindow()
{
QMessageBox::information(this,"ShowMainWindow","ShowMainWindow");
raise();
this->activateWindow();
}

The QMessageBox is displayed but no child window is closed nor the mainwindow is displayed

For activating the mainWindow I used the code


ui.setupUi(this);

and in ui_mainwindow.h "this" is QMainWindow type


void setupUi(QMainWindow *MainWindow)

what to do now?

nish
5th June 2009, 13:21
you said that your main window was hidden? if u called hide() then you should call show() in MainWindow::ShowMainWindow()

try it


void MainWindow::ShowMainWindow()
{
show();
}

Qt Coder
6th June 2009, 12:52
I want to call one of my mainwindow function on close event of child window ,how to connect this signal..


Previously I tried


connect(this,SIGNAL(destroyed()),this->parent(),SLOT(f_max()));


but as I m closing a child window using
this->close()

so "destroyed event "is not getting triggered ...

nish
6th June 2009, 15:29
try these


this->close();
MyMainWindow*p=(MyMainWindow*)this->parent();
p->f_max();

or


void child::closeEvent(QCloseEvent*)
{

MyMainWindow*p=(MyMainWindow*)this->parent();
p->f_max();

}

or


MyMainWindow*p=(MyMainWindow*)this->parent();
connect(this,SIGNAL(destroyed()),p,SLOT(f_max()));

Qt Coder
8th June 2009, 07:16
MyMainWindow*p=(MyMainWindow*)this->parent();


In above code ,In place of "MyMainWindow" what should I put?

in mainwindow .h class is decraled as..


class MainWindow : public QMainWindow
{
}


cant we connect a close event to parent window function???

I just need to detect the close event of this child window and connect my f_max() function to that signal

nish
8th June 2009, 09:19
put MainWindow instead of MyMainWindow and use the closeEvent code i showed u