PDA

View Full Version : Inactive window Updation



csvivek
1st April 2008, 07:57
Hi,

I have a requirement wherein, i need the handler for the main window of the application.
For this i have used the code snippet,

dial=(Ui_Dialog *)qApp->activeWindow(); (Ui_Dialog being the main window of application)

This has one problem the data is not updated if the window is Inactive.
Can anyone suggest what is to be done for this ?

jpn
1st April 2008, 08:08
Introduce a direct pointer to the window, make it a singleton class, or find the window from the list of QApplication::topLevelWidgets()...

csvivek
1st April 2008, 08:17
I tried using the topLevelWidgets function,


foreach (QWidget *widget, QApplication::topLevelWidgets()) {


if( widget->isWindow ())
{
dial = (Ui_Dialog *)widget;
printf("hiding the window\n");
}
}
But i am getting segmentation fault.
This might be because the application has more than one TopLevelWidget.
In such a case how to i find a exact match for (Ui_Dialog *) ?

jpn
1st April 2008, 09:14
First of all, QApplication::topLevelWidgets() returns a list of the top-level widgets (windows) in the application so there is no need to check if they are windows because they are. Secondly, don't use C-style cast, which makes no sanity checks at all, thus you'll get a crash when using something as Ui_Dialog which is not a Ui_Dialog. You should use dynamic_cast instead. But make sure to notice how dynamic_cast works (you should check the return value)!