Close button must close 2 windows
-
Dear,
I've got 4 windows, 1 has the close button etc.., the other 3 windows have the close button disabled with "z.setWindowFlags ( Qt::CustomizeWindowHint | Qt::WindowTitleHint);" , now is it possible if the user clicks the close button of that one window that the other also closes? I don't find something usefull on google, can someone help please?
Kind regards,
-
Just connect the clicked signal of the button to the close signal of every window.
@
connect(closeButton, SIGNAL(clicked()), window1, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), window2, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), window3, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), window4, SLOT(close()));
@ -
Oké i've something like this:
@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(closeButton, SIGNAL(clicked()), MainWindow, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), Form, SLOT(close()));
}
@but it doesn't compile?
Kind regards, thanks for your help already.
-
You need to provide at least the compile error message(s) in addition.
-
I think you need to make point via ui if you use Designer to layout form.
@connect(ui->closeButton, SIGNAL(clicked()), ui->MainWindow, SLOT(close()));
connect(ui->closeButton, SIGNAL(clicked()), ui->Form, SLOT(close()));@It's my guess. You should provide error messages to know exact bug.
-
Sorry forgot to give the error message, i've done it with the ui pointer and these errors shows up:
http://imageshack.us/photo/my-images/228/errk.png/
@
In constructor MainWindow:: MainWindow(qwidget*):
class ui::mainwindow has no member named closebutton
invalid use of class ui::mainwindow
class ui:: mainwindow has no member named closebutton
class ui::mainwindow has no member named form
@thanks for the help
-
I would guess, by "closebutten" browser90 means the button in the window's title bar, not a "regular" UI button. In this case, you should reimplement "QWidget::closeEvent() ":http://doc.qt.nokia.com/4.7/qwidget.html#closeEvent in your main widget class.
Something like this should do the trick:
@
// to your .h file in the protected section:
void closeEvent ( QCloseEvent * event );// add this to the implementation:
void MainWindow::closeEvent ( QCloseEvent * event )
{
Form->close();
OtherWindow->close();
QMainWindow::closeEvent(event);
}
@ -
Thanks :-)
-
[quote author="browser90" date="1321300907"]Oké i've something like this:
@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(closeButton, SIGNAL(clicked()), MainWindow, SLOT(close()));
connect(closeButton, SIGNAL(clicked()), Form, SLOT(close()));
}
@but it doesn't compile?
Kind regards, thanks for your help already.[/quote]
Seems to me you are confusing classes with objects (instances of classes). You can not connect to a class, you connect to an object.