eventFilter in Console App
QT Version: 4.4.1
OS: RHEL 5
I am attempting to create a console application that uses QLocalServer/QLocalSocket for interprocess communication.
In the program, I stay in the event loop waiting for connections.
If the user presses a key, I want to exit the program.
I have remplemented the eventFilter method and added a installEventFilter(this) call to the constructor of the SNOOPER class:
Code:
{
Q_OBJECT
public:
SNOOPER
(QString sIP
);
// Constructor ~SNOOPER(); // Destructor
...
public slots:
void connectClient();
void readParts();
};
{
bool bRval = false;
if (e
->type
() == QEvent::KeyPress) {
qDebug("KeyPress event detected.");
bRval = true;
exit(0);
}
else
{
qDebug("Non-KeyPress event detected.");
}
return bRval;
}
I received the following output when I run the program, but I do not get any key events:
Code:
Non-KeyPress event detected.
Non-KeyPress event detected.
Please let me know what I am missing.
Thanks!
Karl
Re: eventFilter in Console App
KeyPressEvents are sent only to widgets therefore console applications won't receive them.
Re: eventFilter in Console App
Is there a good way to trap <control>-C so that I can at least shutdown the QLocalServer if they exit that way?
Currently, it works like this:
1. Start the program.
2. Hit Control-C to stop it.
3. Start it again, and I get a socket busy error.
4. Start it again and it works.
If I could somehow skip step 3, I'd be alright.
Karl
Re: eventFilter in Console App
Use signal() or sigaction() depending on the system you are using.