PDA

View Full Version : How to start the log file when key combinations pressed??



Gokulnathvc
8th April 2011, 08:13
how to start the log file when CTRL+ALT+T is pressed and if it presssed again it should stop.... how it can be done...

wysota
8th April 2011, 10:35
What is it exactly that you don't know how to implement?

Gokulnathvc
8th April 2011, 10:37
I want to start the log file creation when CTRL+ALT+L is presssed and have to stop it when the same combination has been clicked.. please help me..

wysota
8th April 2011, 10:39
I understand what you want, I'm asking what are you having problems with? Tell us what you have already tried and what didn't work.

Gokulnathvc
8th April 2011, 10:50
void QCDevice::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Control && Qt::Key_Alt && Qt::Key_V) {

QMessageBox::warning(NULL,"Keypress","Keypressed",QMessageBox::Ok);
}

I have tried this one, but after pressing the key combination also the message box is not shown..

}

wysota
8th April 2011, 10:51
Is QCDevice a widget?

Gokulnathvc
8th April 2011, 11:07
No its a dialog

wysota
8th April 2011, 11:17
A dialog is also a widget :) Ok, does it have keyboard focus?

Furthermore your code is incorrect:

if (event->key() == Qt::Key_Control && Qt::Key_Alt && Qt::Key_V)
this can be translated to:

if(event->key() == Qt::Key_Control && 0x01000023 && 0x56)
which again translates to:

if(event->key() == Qt::Key_Control && true && true)
and then to:

if(event->key() == Qt::Key_Control)
which as you probably guess is not what you want. Read what QKeyEvent::key() is and use it with conjunction with QKeyEvent::modifiers(). Or just use QShortcut.

Learning a bit more C++ wouldn't hurt either.

Gokulnathvc
8th April 2011, 11:31
How to perform those key combinations in it?? please help me with the above codes.

wysota
8th April 2011, 11:34
What didn't you understand from my previous post? Make sure you widget accepts focus, use QKeyEvent::key() in conjunction with QKeyEvent::modifiers() or use QShortcut. If you expect me to provide full working code then that's not going to happen, I rarely do that in the Newbie forum. And please correct your profile information, somehow I doubt you're using Qt3 or Qt/Embedded.

ChrisW67
8th April 2011, 22:57
please help me with the above codes.
You are using logical AND where you want bit-wise AND.

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Logical_operators

Gokulnathvc
9th April 2011, 06:20
I have solved that


if ((event->type()==QEvent::KeyPress) && (event->modifiers() & Qt::ControlModifier) &&
(event->modifiers() & Qt::AltModifier)&& (event->key()==Qt::Key_L))
{
QMessageBox::warning(NULL,"keypress","key pressed",QMessageBox::Ok);

}

Gokulnathvc
11th April 2011, 07:29
The above code works fine in xp .. But it Fails in windows 7.. please help me

Gokulnathvc
11th April 2011, 10:37
In window 7 even the key press event is not called... please help me in fixing this...

wysota
11th April 2011, 11:01
Does the widget accept keyboard focus?

Gokulnathvc
11th April 2011, 11:11
No. it is not accepting it. but it works good in xp

wysota
11th April 2011, 11:13
No. it is not accepting it.
So it won't handle key events.

Gokulnathvc
11th April 2011, 11:19
Whether it can be applied using the dialogs instead

wysota
11th April 2011, 11:20
Whether it can be applied using the dialogs instead

I have no idea what you mean.

Gokulnathvc
11th April 2011, 11:25
Is it possible to apply the key press events for the dialog based applications???

wysota
11th April 2011, 12:13
Yes but your dialog needs to accept focus to receive key events. How many times do I have to say it for you to understand?

Gokulnathvc
11th April 2011, 12:19
How to make the dialogs to accept the focus??

wysota
11th April 2011, 12:38
Go to QWidget API and keep reading it until you find something that might indicate that it's related to focus.

Gokulnathvc
12th April 2011, 10:50
How to capture the key press events in QT in windows7?? CTRL+ALT+ some alphabet combination's. if we press this combination.. the particular event function should be called...

mcosta
12th April 2011, 11:56
If you have a GUI application you can use QShortcut or QAction.

Gokulnathvc
12th April 2011, 13:37
I have used the following code.. it works fine in xp(Qt 1.3.1) but it is not working in windows 7.,(Qt 4.3)::


QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+M"), this);
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(showmessage()));

wysota
12th April 2011, 14:06
For the last time: shortcuts, key events and such work in terms of focus. One of children of the window containing the shortcut needs to have focus for the shortcut to trigger.