How can I handle cleanup to my application with just a single console window (no GUI), when the user click the 'X' button in the right-top corner? Thanks.
How can I handle cleanup to my application with just a single console window (no GUI), when the user click the 'X' button in the right-top corner? Thanks.
I suppose event is console & GUI to
****.cpp
Qt Code:
/* close class destructur */ { qt_unlink(LOCK_FILE_APPLICATION); if (isOpen()) { int totalsx = nametableall.size(); if (totalsx > 0) { dumptofilesql(LAST_SQL_SESSION); } SqlLog("Class Shop_Main close.... on open"); } else { SqlLog("Class Shop_Main close.... on not open"); } DownDirRemove(DB_IMPORT_CACHEDIR); e->accept(); }To copy to clipboard, switch view to plain text mode
****.h
Qt Code:
protected: //To copy to clipboard, switch view to plain text mode
#include <QCloseEvent>
template file ... take the designer ui class top name & put to...
http://ppk.ciz.ch/qt_c++/qt/res.html ajax running only on ie6
http://ppk.ciz.ch/qt_c++/qt/ reading ***.txt file
Last edited by patrik08; 27th May 2006 at 10:35.
I think it not be helfull for console app , becouse it havent QWidget
a life without programming is like an empty bottle
then make a simple traditional class ~destructor...
A console app typically doesn't have an event loop, and it most certainly doesn't have a windowing (windows or X) event loop. There is no way to intercept the close event without a windowing event loop, that I know of.
Closing a console window usually simply destroys its subprocesses.
Now, if you want to try to get way under the covers --- you might try to find your parent process (the console) and see if the os sends some sort of signal or interrupt you can intercept when the parent process gets a notification to shut down. You might be able to clean up and shut down, then. (I don't know of such a signal off the top of my head. You're in for a lot of OS specific research.)
Another approach might be to set a system hook that somehow knows your process and your parent process (you'd register it on startup), and can intercept raw events before they're dispatched to the desktop. When your console gets a WM_CLOSE (or system equivalent) for the console window, you can intercept it and shut down your process (but your process has to have a looping thread or something to act on it, of course.)
Non-trivial.
rickb
A normal mail server make lock.file ....
by a new process check if this fake file (empty or put time(NULL)) have a filetime older or new .... and delete file...
if (!lockfile exist) {
create it...
} else {
exit apps...
}
or if (lockfile exist) {
check filetime and or delete...
}
this console apps have sqls db connect? or sockets?
I'm not sure what either e-mail or sql connection has to do with the console.
When the OS opens a console, I know of no lock file that gets set up, or why it would need one. It would be extremely internal to the OS.
Let's try again - are you opening the console window from your program, or are you starting your program from within a console window?
rickb
My code is copied as below, as you see i use the 'console mode' of QApplication, however I dont know where to put the cleanup code when the user simply press the 'X' button in console window.
Qt Code:
//------------------------------------------------------------------------------ #include <QtGui> #include <QtSql> //------------------------------------------------------------------------------ #include "thread_main.h" //------------------------------------------------------------------------------ bool initializeConnection() { qSqlDatabase.setDatabaseName("some_db"); return qSqlDatabase.open(); } //------------------------------------------------------------------------------ int main(int iMain,char** cMain) { if (!initializeConnection()) { qDebug()<<"initializeConnection: "<<QSqlDatabase::database("SOME_DB").lastError().text(); } ThreadMain threadMain; threadMain.start(); return qApplication.exec(); } //------------------------------------------------------------------------------To copy to clipboard, switch view to plain text mode
Last edited by wysota; 28th May 2006 at 09:01.
Two possible places:
1. SIGTERM signal handler if on unix
2. QApplication subclass destructor.
Remember that your app gets killed if you close the console window containing it.
BTW. Why are you spawning a separate thread? You don't need it...
That old http://qt4ds-monkey.sourceforge.net/
code made its own CONSOLE. (http://ciz.ch/svnciz/dialog_qt/qt4_a...ents/QConsole/)
So can one it surely well control...
Then it gives to still bring
cron jobs around processe in order... Wincron on window http://www.tomasello.com/software/wincron/
Or ... in your code make connection by a class ... and destructor works....
Bookmarks