Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

c++ - Make Qt application not to quit when last window is closed

I've created a Qt application that acts mostly as a daemon, but occasionally shows a dialog.

Now, I know the default behavior is to close the application when the last window closes, but for my program, I need it to continue running. How do I change the behavior of my application?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can set the QApplication::quitOnLastWindowClosed property to false:

...
QApplication qApp;
qApp.setQuitOnLastWindowClosed(false);
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...