PDA

View Full Version : Accessing google tools from Qt



rohitkk
2nd April 2014, 08:02
Hi All,

Is there any way to turn google tools on or off through Qt on QLineEdit focus.
Actually i am using multilingual application & I want different language on different line edits.
Thanks in advance.

Regards,
Rohit.

wysota
2nd April 2014, 08:17
Eeeemmm.... whaaat?

rohitkk
2nd April 2014, 08:25
I want to access a different application(Google Tools) from Qt.
I want to turn google tools on or off*(pressing Ctr+G) based on which qlineedit it has focussed.

Or can i press Ctr+G (Not through keyboard externally) on line edit focussing.

Or firing Keyboard event.

wysota
2nd April 2014, 08:33
What google tools? What does Qt have to do with this? Do you mean google input tools (http://www.google.com/inputtools/)? Could you be more specific about what you have now, what you want and how is what you have different from what you want?

rohitkk
2nd April 2014, 08:41
Yes it is google input tools.
I want google input tools to be turned off & on based on the line edit on which I am focusing.
So, on focus event for a line edit I want Ctrl+G(viz. a shortcut to turn google tools on & off) to be pressed.
Can I do this ? Is it possible to press /Call keyboard event or can I directly access Google tools application from qt.

Help will be appreciated.

My Application is a multi language application in which user inputs a different language for a certain line edit & a different language on different line edit.
Hence, pressing Ctrl+G I have to toggle the language each time , but now i want it to be done through programmatically.

wysota
2nd April 2014, 08:57
If the tool does not provide any API to control it then most likely you can't do it. If the tool provides some API you can use then most probably you can do it. Which is the case I doubt anyone on this forum has any knowledge of and it would be better to ask at some google site or read their manual.

rohitkk
2nd April 2014, 09:29
Its not about whether google tools provide it , Its about whether Qt allows to do it. If Yes then how?

anda_skoa
2nd April 2014, 09:31
I want to turn google tools on or off*(pressing Ctr+G) based on which qlineedit it has focussed.

Create a QShortCut for CTRL+G and in the slot check which of your QLineEdit has focus (if any).



Or can i press Ctr+G (Not through keyboard externally) on line edit focussing.

You can trigger the slot directly, e.g. through subclassing QLineEdit and reimplementing focusInEvent() or by using an event filter.



Or firing Keyboard event.

You can do that as well. Create a QKeyEvent and use QApplication::postEvent() or QApplication::sentEvent() to whatever widget you'd like to be the receiver.

All of that is obviously totally independent of what you do when the short cut is triggered.

Cheers,
_

rohitkk
2nd April 2014, 10:28
Create a QShortCut for CTRL+G and in the slot check which of your QLineEdit has focus (if any).

You can do that as well. Create a QKeyEvent and use QApplication::postEvent() or QApplication::sentEvent() to whatever widget you'd like to be the receiver.

_

Can you please elaborate on how to do this.

rawfool
2nd April 2014, 11:08
Is this what you are looking for ?


QShortcut * shortcut = new QShortcut(Qt::CTRL + Qt::Key_G);
connect(shortcut, SIGNAL(activated()), objectOfCorrespondingClass, SLOT(getFocussedLineEdit()));

// -- slot
void YourClass::getFocussedLineEdit()
{
if(lineEdit_1->hasFocus())
{
// Do necessary
}
else if(lineEdit_2->hasFocus())
{
// Do necessary
}
else if(lineEdit_3->hasFocus())
{
// Do necessary
}
else
{
// ...
}
}

rohitkk
2nd April 2014, 11:40
Is this what you are looking for ?


QShortcut * shortcut = new QShortcut(Qt::CTRL + Qt::Key_G);
connect(shortcut, SIGNAL(activated()), objectOfCorrespondingClass, SLOT(getFocussedLineEdit()));

// -- slot
void YourClass::getFocussedLineEdit()
{
if(lineEdit_1->hasFocus())
{
// Do necessary
}
else if(lineEdit_2->hasFocus())
{
// Do necessary
}
else if(lineEdit_3->hasFocus())
{
// Do necessary
}
else
{
// ...
}
}


I am able to check that whether line edit is in focus but i am not able to fire the 'Ctrl+G' event after focusing.
Below is my code snippet,


bool DemoDialog::eventFilter(QObject *target, QEvent *event)
{
if (target == ui->leAge) //On focussing Age line edit i want to fire 'Ctrl+G' event
{
if (event->type() == QEvent::FocusIn)
{
qDebug()<<"Inside Event";
QKeyEvent *evnent=new QKeyEvent(QEvent::KeyPress,Qt::CTRL+Qt::Key_G,Qt:: NoModifier,QString(""));
QApplication::postEvent(qApp,evnent); //This is not working at all
}
}
return QObject::eventFilter(target, event);
}

Lesiok
2nd April 2014, 12:05
Is the line 8 should not be a :

QKeyEvent *evnent=new QKeyEvent(QEvent::KeyPress,Qt::Key_G,Qt::ControlMo difier,QString(""));

wysota
2nd April 2014, 12:42
What exactly you expect to happen when you send Ctrl+G to your application object? If you expect another application to respond to it then it is not going to happen.

rohitkk
2nd April 2014, 13:29
What exactly you expect to happen when you send Ctrl+G to your application object? If you expect another application to respond to it then it is not going to happen.

Yes, I want google input tools to get turned off.
But Why? Qt doesn't support to interact with other application?


Is the line 8 should not be a :

QKeyEvent *evnent=new QKeyEvent(QEvent::KeyPress,Qt::Key_G,Qt::ControlMo difier,QString(""));

No , It is not working.

Added after 12 minutes:


Is the line 8 should not be a :

QKeyEvent *evnent=new QKeyEvent(QEvent::KeyPress,Qt::Key_G,Qt::ControlMo difier,QString(""));
This is not working

Lesiok
2nd April 2014, 13:30
QCoreApplication::postEvent send event to any object in this application.

rohitkk
2nd April 2014, 13:38
This isn't working either

QCoreApplication::postEvent send event to any object in this application.

Lesiok
2nd April 2014, 13:49
This isn't working either

What it means ? You are sending event to the object pointed by qApp variable. Did this object know what to do ?

P.S.
Are you sure you know what you're doing ?

wysota
2nd April 2014, 14:06
Qt doesn't support to interact with other application?

Definitely not this way. You are sending an internal event to an internal object so don't expect some other entity to receive and understand that. It's like you were driving a car, turning your driver wheel right and expecting some concrete car in a different country to start ringing its horn.

rohitkk
2nd April 2014, 14:39
Then what is right way to do it?

Definitely not this way. You are sending an internal event to an internal object so don't expect some other entity to receive and understand that. It's like you were driving a car, turning your driver wheel right and expecting some concrete car in a different country to start ringing its horn.
I am really getting confused bcoz of this shit.

Added after 22 minutes:

As of now u must have understand my requirement. If there are any suggestion on how to do it will be highly appreciated.
Please co-ordinate as i am new to qt framework.

Regards,
Rohit

wysota
2nd April 2014, 14:44
Then what is right way to do it?
The right way is to use the API offered by the framework you want to interact with. Qt has nothing to do with it, you have to find a way to send appropriate commands to the other framework and only then you can look for ways of doing it with Qt.

high_flyer
2nd April 2014, 14:51
@Rohit:
In order to access google tools, they have to offer a public API.
If you don't have the libs and the API to access them, then its not possible to access them be it from Qt or any other place.

The problem you have in this thread is a communication problem.
It seems you do not fully understand what it is you are asking.
Qt can not allow access to anything.
Its the software being accesses, that has to allow access to it.
If your google tools offer such API you can access them from any application be it written with Qt or not.

So if you want to move forward - do what wysota suggested above:
Ask around in forums that deal with these input devices.
If they allow access through their API - most likely these forums will offer a "hello world" example, free of Qt or any other dependency.
THEN, you might want to use this in a Qt application, but then the access is not going to be your problem any more where we can help you further should you need any Qt related help.

Accessing external API is not something related to Qt and thus off topic for this forum.

I hope this helps you further.

sulliwk06
2nd April 2014, 15:54
If I might interject here for clarity's sake.

So Ctrl+G toggles these google tools on and off. There is no way to programmatically send Ctrl+G to the system so that any applications can catch it? I know I've seen applications that can remap keys. Are those not intercepting key press events and emitting a different one? Or is it just that QT doesn't have a class capable of doing that?

rohitkk
3rd April 2014, 05:41
If I might interject here for clarity's sake.

So Ctrl+G toggles these google tools on and off. There is no way to programmatically send Ctrl+G to the system so that any applications can catch it? I know I've seen applications that can remap keys. Are those not intercepting key press events and emitting a different one? Or is it just that QT doesn't have a class capable of doing that?
Yes , I was thinking the same way.....

wysota
3rd April 2014, 08:40
If I might interject here for clarity's sake.

So Ctrl+G toggles these google tools on and off. There is no way to programmatically send Ctrl+G to the system so that any applications can catch it? I know I've seen applications that can remap keys. Are those not intercepting key press events and emitting a different one? Or is it just that QT doesn't have a class capable of doing that?

Ctrl+G is registered as a global hotkey for the application. When the user presses Ctrl+G the system most likely intercepts events coming from the keyboard driver and interprets them itself. I strongly doubt sending Ctrl+G "to the system" would trigger the hotkey. Maybe WinAPI offers a way to artificially trigger a hotkey but this is still out of scope of Qt.

http://lmgtfy.com?q=winapi+trigger+global+hotkey