×
Namespaces

Variants
Actions

Talk:Detecting focus lost & gained events in Qt for Symbian

From Nokia Developer Wiki
Jump to: navigation, search

Contents

AlterX - signal not possible in QApplication?!

Hi, i'm using that schema and i replaced qDebug with two my own signal...when i compile the application, the error:

In function `MyBackgroundApp::symbianEventFilter(QSymbianEvent const*)':
  C:/Sviluppo/QkSolitaire/mybackgroundapp.cpp:14: undefined reference to `MyBackgroundApp::appGoingInForeground()'

MyBackgroundApp is a subclass of QApplication and appGoingInForeground is a signal defined in MyBackgroundApp.

Moreover if i try to connect the signal from within QML file (after i've used setContextProperty), it shows me that is undefined!

AlterX 16:16, 19 August 2011 (EEST)

Hamishwillee - Tried the forums

Best to post question on the discussion boards, unless specifically about the article.

The problem is mos likely that your application is not a QObject based class, or you've omitted the Q_OBJECT macro in its declaration.

hamishwillee 05:15, 22 August 2011 (EEST)

Ic000001 - How to do this in a Qt Quick application?

Hi there,

Apologies - I'm really rusty on C++ and don't know much raw Qt.

I have a Qt Quick Application "using template from Qt Creator" ... how can I implement this? (i.e. suspending Audio when my Qt Quick app is suspended)

My main.cpp:

  1. include <QtGui/QApplication>
  2. include "qmlapplicationviewer.h"

int main(int argc, char *argv[]) {

   QApplication app(argc, argv);
   QmlApplicationViewer viewer;
   viewer.setMainQmlFile(QLatin1String("qml/QtQuickApplication/main.qml"));
   viewer.showExpanded();
   return app.exec();

}


The project also has the qmlapplicationviewer.cpp and .h files.

Your help would be much appreciated!

ic000001 10:01, 22 October 2011 (EEST)

A1291762 - Re: QML Application

Ic000001, You can replace QApplication with the MyApplication class described. You just need to find a way tp have it poke into your QML (assuming you want to handle the event from within QML). Something like this:

class MyApplicatoin
{
...
QmlApplicationViewer *viewer;
bool symbianEventFilter()
{
...
case EEventFocusGained:
viewer->rootObject()->setProperty("appFocused", true);
break;
case EEventFocusLost:
viewer->rootObject()->setProperty("appFocused", false);
break;
...
 
MyApplication app()
QmlAppViewer viewer;
app.viewer = &viewer;
Then in the element you define in main.qml, define the appFocussed property and an onAppFocussedChanged: signal handler (that will fire when the app gains and loses focus).

a1291762 16:21, 26 October 2011 (EEST)

Hamishwillee - No, for QML you'd use the "Symbian" component, foreground property

http://doc.qt.nokia.com/qt-components-symbian/qml-symbian.html#foreground-prop

This changes when the app gains and loses focus.

hamishwillee 07:32, 1 December 2011 (EET)

 

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×