If this is what your program looks like:
#include <QtGui>
{
public:
init();
}
void init() {
close();
}
};
int main(int argc, char **argv)
{
MainWindow w;
w.show();
app.exec();
}
#include <QtGui>
class MainWindow: public QMainWindow
{
public:
MainWindow(QWidget *p=0): QMainWindow(p) {
init();
}
void init() {
close();
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow w;
w.show();
app.exec();
}
To copy to clipboard, switch view to plain text mode
You call init() in the constructor, the widget has not been displayed yet, you have never reached the main event loop, so close() is meaningless. The constructor completes either way, the next line of your code is widget->show(), which dutifully gets executed and then you fall through in the main event loop. QCoreApplication::exit() doesn't work in that position either.
You could delay init() until the event loop is reached, or call it explicitly and have it return a bool indicting success/failure which decides whether to continue into the main even loop or not. Without more of your code we can only guess.
Bookmarks