Qt: receive keyboard events when my application doesn't have focus - qt

I am writing a Qt application. At the first stage I want to receive all key press events, system-wide, without creating any widgets.
Is this possible in Qt, or do I have to hook into the underlying window system? (This needs to be cross-platform.)

Related

How notify user when my application is not running in qt?

I have a qt quick 2 application that I run it in android.Now I want to show message to my users ,For example I want to send a get Request to my server to find out "Is this user has any message from another user or not?" and if has new message show a notification to my user.This should be run when my application is not runnng.
But I didn't see any Class that i can do this in qt?
How can I Do this?
Qt for Android lists what you can do with Qt. Qt Android Extras includes classes that wrap the most important functions of few Android package methods, but is not intended to provide out of the box methods for everything in Android.
You can write Java Classes to implement detailed or specialized Android functions, those then can easily be implemented with Qt using the rich Android Extras JNI APIs.
In Qt Examples, Qt Notifier, serves very similar or same functionality you asking for.
You can run Android services (long running apps hiding user interface) , by Creating Android Services And QAndroidService Class

How to get mobile app lifecycle events on QtApp

I am programming an app in Qt 5.9.4 commercial license. My app runs on Android and iOS.
Question:
Is there a way in Qt to detect usual mobile device events like:
- Device display switched off
- Device went to background after user presses home button on iOS/Android
- back button pressed on Android etc
There are a bunch of these events that each of the platform Android and iOS trigger.
If there is class/module in Qt that is relaying these events back then I wouldn't have to do the extra work of writing native(java and objective-c) classes to get these events inside my QtApp.
Most of these events are handeled by Qt itself and you can get them through classical means. Qt tries to hide android specific stuff as good as possible and delivers those though events etc. as you would get them on a desktop application.
The back button press triggers a QCloseEvent that is sent to the primary window. You can install an event filter on the object from C++ it to intercept it. For qml it's the Window::closing signal.
Since Qt does not support background execution of activities, the background press is propably reported as close event as well - or it quits the application directly.
For the DIsplay switch of I don't now for sure, but maybe the QGuiApplication::applicationStateChanged signal does report it as Qt::ApplicationSuspended or another of those states - simply try it out! (this might be the case for other events as well)
Short Hint for Android: If you however want something Qt does not handle, you can always just create a custom Java activity that extends the QtActivity and use it in the manifest. From there on you can use the JNI to interact with Java from C++ and vice versa. If you need to do so, have a look at the Qt Android Extras - They make using the JNI much easier and provide a bunch of nice wrapper classes and utility methods in the QtAndroid namespace that can come in very handy.

How to access the QObject of a Qt UI from another QT application?

I am intending to implement a simple test QT application in linux which launch a QT UI application running on an Embedded linux platform to verify it. I want to be able to send signals from the test application to the UI, for instance to press a button on the GUI, then check if the signal has made the expected change on the QT UI application. I know there are some tools like Squish, Testability Driver that can hook a running QT application and access the properties of each graphical element (e.g. button).
I have searched a lot, but I could not find any suitable solution. If somebody can introduce a suitable solution?
On Unix platforms you can use dbus. Otherwise you have to roll your own mechanism, or use a third party tool.

QtCreator Designer signal/slot connections inconsistent with generated code

I'm working on a Qt project in QtCreator. The project has a dialog box with several UI elements, some of which have to be enabled/disabled according to what the user does. (i.e. If the user selects a radio button, then the form field has to be enabled.)
When I add a new signal/slot connection or delete an existing through the Qt Designer tool, the change shows up just fine in the preview. When I compile the application, though, the window still behaves exactly as it did before.
I investigated this by checking out the ui_WindowName.h file that the Qt Designer creates. Near the end of the setupUi function is a set of connect() calls. These connect() calls are consistent with the slot and signals that existed earlier today, but they do not reflect the changes I have made through Qt Designer since.
If I manually change the ui_WindowName.h file, then the UI works. But, of course, my changes get overridden if I ever try to chance anything from Qt Designer.
Even when I quit QtCreator and open it again, the Designer still shows the changed slot/signal connections while the auto-generated code does not reflect the changes.
Am I doing something wrong? Is there some way to delete whatever cache the Designer is storing or something to get things back in sync?
Thanks!
(One other thing: I'm using the stand-alone Qt Creator, not trying to develop in Visual Studio. The only other similar problem I could find on the web was from someone developing in Visual Studio, which doesn't support the automated signal/slot stuff.)
As usual, the answer is obvious once you realize it.
I moved the project in the course of working on it. There's a .pro.user file that keeps track of where the project is located. Without realizing that, I moved it along with the rest of the files.
As a result, I was editing one copy of the project and running the other.
The moral of the story: If you move a Qt project, remember to update your .pro.user file.
(Or you can just delete it. Qt Creator will prompt you to re-create it when you open the project.)

USB mouse hotplugging in DirectFB/QT Embedded

Is there any way to achieve hot-plugging of USB mouse in DirectFB 1.2.9 or Qt Embedded 4.7.3?
Currently my application stack is thus..
-----------------
GUI
-----------------
Qt Embedded 4.7.3
-----------------
DirectFB 1.2.9
-----------------
/dev/input/eventX
-----------------
DirectFB opens the Linux input device node. Qt uses a QSocketNotifier to wait on the DirectFB event buffer and sets up a slot to read the mouse data. But on hot-plugging, DirectFB does not open the device node and no mouse events are generated.
As far as I understand so far, hot-plugging is not supported by DirectFb..
I tried disabling DirectFB's handling of the Linux input device (removing the dev node from linux-input-devices= option in directfbrc), and set QWS_MOUSE_PROTO="linuxinput:.." but this did not work for some reason. Seems no mouse events were generated. Even if I manage to get it to work, I don't think QT provides any support for hot-plugging either.
So is my only alternative to sub-class QMouseDriverPlugin and QWSMouseHandle classes?. For this, I am yet to figure out how to make QT use the sub-classes I implement. i.e, Once I implement these classes how do I link them into the QT input device handling frame-work, so that I can set something like QWS_MOUSE_PROTO="mylinuxinput:.."?
As far as I can remember, I encountered no issue with mouse or keyboard hotplugging in Qt Embedded 4.7.2 (without DirectFB). If you want to subclass yourself, modify the plugin starting from the linuxinput plugin. You'll find that in Qt sources: this is the directory where the plugins are placed, but some classes are included in other directories.
Also, are you getting data in your linux device after pluggin in? Did you try to cat the device?

Resources