PDA

View Full Version : How to write the "Enter" event



Sarma
24th March 2006, 11:22
Hello everyone,
I have a dialog box as a child of a parent widget.Iam sending the snapshot of the dialog box.

When a string is entered in the lineedit and "enter" key is pressed, the "forward" button should work which is not happenning with my code. Can any body help me in this regard.

Thanks & Regards,
Sarma.

jpn
24th March 2006, 11:27
connect(lineEdit, SIGNAL(returnPressed()), fwdButton, SIGNAL(clicked()));


[EDIT] Changed SLOT->SIGNAL, thanks wysota for pointing this out ;)

amulya
24th March 2006, 11:28
hi sarma,

could u resend the screenshot again...i guess it didnt get attached:)

Cheers,
Amulya

amulya
24th March 2006, 11:30
sorry...disregard my above post:p

wysota
24th March 2006, 11:44
Set "Forward" as the default button (setDefault(true) on the button).

Sarma
24th March 2006, 12:06
Iam sorry to say this that both the methods are suggested above are not working.


connect(lineEdit, SIGNAL(returnPressed()), fwdButton, SLOT(clicked()));

This is showing two errors as:


QObject::connect: (sender name: 'unnamed')
QObject::connect: (receivers name: 'unnamed')

And I couldnot understand why this setDefault(true) method is also not working. Could you please suggest me a better answer.

Thanks & Regards,
Sarma.

Sarma
24th March 2006, 12:44
When I have used setDefault(true) method, the "Forward" button has got the focus which was not there previously. Even then, it is not working when "Enter" key is pressed.

Thanks,
Sarma

jpn
24th March 2006, 13:05
This is showing two errors as:
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receivers name: 'unnamed')

Did you replace the variable names lineEdit and fwdButton with appropriate names you have used in your code?

wysota
24th March 2006, 13:55
In Qt3 pushbuttons don't have the "clicked" slot. You have to forward the signal (so instead of SLOT(clicked()) use SIGNAL(clicked()) ).

The setDefault() approach should work provided that your dialog inherits QDialog. Does it?

Sarma
27th March 2006, 06:55
hello sir,

Thanks a lot once again. well thats working perfectly. Actually my application doesnot inherits QDialog. And one more thing sir, can we use


QObject::connect(sender,SIGNAL(..),receiver,SIGNAL (...));


I thought we should use a signal and a slot.Thats why i couldnot do it.

Thanks and Regards,
sarma.:)

jpn
27th March 2006, 09:17
Yes, it is possible to connect a signal directly to another signal. This will emit the second signal immediately whenever the first is emitted.