PDA

View Full Version : hide() quits?



Morea
23rd February 2006, 19:27
I have a strange problem. I made a simple app with a button, and connected the buttons clicked() to hide() of the mainwindow. When clicking this button the app crashed in windows 2000. I'm using Qt 4.
The program works fine in Linux. Strange. Is this a known bug or something else important that I have missed?

This is main.cpp

#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{ QApplication app(argc, argv);
MainWindow *MainForm = new MainWindow;
MainForm->show();
return app.exec();
}


This is mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "ui_mainwindow.h"

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget * parent = 0);
private:
Ui::MainWindow ui;
};

#endif


this is mainwindow.cpp

#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent, 0)
{ ui.setupUi(this);
}


this is the ui file

<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>248</height>
</rect>
</property>
<property name="windowTitle" >
<string>Test QT DevCPP</string>
</property>
<widget class="QWidget" name="centralWidget" >
<widget class="QPushButton" name="pushButton" >
<property name="geometry" >
<rect>
<x>40</x>
<y>80</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text" >
<string>PushButton</string>
</property>
</widget>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel" >
<x>81</x>
<y>114</y>
</hint>
<hint type="destinationlabel" >
<x>216</x>
<y>146</y>
</hint>
</hints>
</connection>
</connections>
</ui>

I can't see anything strange with this, can you?

jacek
23rd February 2006, 19:45
Which Qt version do you use on windows?

Morea
23rd February 2006, 19:46
4.1.0 (open source)
It is compiled without debug.
Mingw 3.4.2 is the compiler.

jacek
23rd February 2006, 19:50
Then there should be no problems. How does it crash?

Morea
23rd February 2006, 19:51
It just disapear. I run the task manager at the same time, it appears there, but when I click it, it disappear. Really strange.

I updated this posting with the exe file (zipped) if some brave OR curios person want to try it out. There also seems to be some kind of a little delay, it doesn't quit/crash directly. But this is hard to tell if it really happens.

jacek
23rd February 2006, 20:11
It just disapear. I run the task manager at the same time, it appears there, but when I click it, it disappear.
It doesn't crash, it just closes itself.


From QApplication docs (http://doc.trolltech.com/4.1/qapplication.html#quitOnLastWindowClosed-prop):
quitOnLastWindowClosed : bool
This property holds whether the application implicitly quits when the last window is closed.
The default is true.
If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.
Access functions:
bool quitOnLastWindowClosed ()
void setQuitOnLastWindowClosed ( bool quit )
See also quit() and QWidget::close().

Morea
23rd February 2006, 20:20
Oh! Thank you very much!
I think it was showMinimized() I was looking for.

Everall
23rd February 2006, 20:29
In my opinion it couldn't be better.
How would you ever do something with your mainwindow if everything is hidden? For instance how would you make it visible again?

Morea
23rd February 2006, 20:39
You are right. I thought it was possible to get it back again.
Learning is fun!

jacek
23rd February 2006, 21:20
I thought it was possible to get it back again.
It will be possible, if you switch that property to false.

wysota
24th February 2006, 01:34
How would you ever do something with your mainwindow if everything is hidden? For instance how would you make it visible again?

For example using timers or global keybord shortcuts. Or a tray icon (but maybe it is treated as a window too? hmm... dunno).

Everall
25th February 2006, 20:02
For example using timers or global keybord shortcuts
never thought about that.

Do you know real world applications that use it?

Thanks

jacek
25th February 2006, 20:12
Do you know real world applications that use it?
http://yakuake.uv.ro/

Everall
25th February 2006, 20:40
Thanks Jacek