Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 8

Qt-interest Archive, March 2002
Open sub-window


Message 1 in thread

I explained myself poorly the last time, probably why I got no replies. I'll 
try again.

I have a main window in my application. There is a button, myPushButton, 
which , when pressed, opens a sub-window. This sub-window is declared as a 
QWidget and contains simple things such as buttons.
When myPushButton is clicked a SLOT named openSubWindow() is called. I have 
the following code which compiles but when the button is clicked the 
sub-window does not appear.

 connect(myPushButton, SIGNAL (clicked()), this, SLOT (openSubWindow()));

void MainWindow::openSubWindow()
{

	SubWindow s;
	s.setGeometry (100, 0, 500, 660 );
 	s.show();
 	
}

Thanks


Message 2 in thread

Your sub-window has no parent. Try:

SubWindow(this);

--
 [ signature omitted ] 

Message 3 in thread

The SunWindow "s" is deleted when the slot function exits. This would be ok if it were a modal dialog, but that would have to be
started with s.exec().
For dialogs that are not model, create the SubWindow on the heap (using "new"), and preferably set the Qt::WDestructiveClose flag so
that you do not have to worry about deleting it. But that depends on your code...

One more thing: setGeometry is not really useful for toplevel widgets. The position is more reliably set with QWidget::move(...),
and the size should better be determined by the layout manager, use QWidget::resize(...) if you want to provide it yourself.

- Soeren


> When myPushButton is clicked a SLOT named openSubWindow() is called. I have
> the following code which compiles but when the button is clicked the
> sub-window does not appear.
>
>  connect(myPushButton, SIGNAL (clicked()), this, SLOT (openSubWindow()));
>
> void MainWindow::openSubWindow()
> {
>
> SubWindow s;
> s.setGeometry (100, 0, 500, 660 );
>   s.show();
>
> }


Message 4 in thread

Hello,

>
> void MainWindow::openSubWindow()
> {
>
> 	SubWindow s;
> 	s.setGeometry (100, 0, 500, 660 );
>  	s.show();
>
> }

SubWindow s is local variable. Try:

	SubWindow *s = new SubWindow;
 	s->setGeometry (100, 0, 500, 660 );
  	s->show();


Regards
Ilir

-- 
 [ signature omitted ]