[Solved] Pause mode doesn´t work



  • Hello, I´m new in qt and I trying to develop an aplication for symbian in javascript and qml, the problem is that I want that my app goes to the state pause when I suspend the aplication to the background.
    How I do this in qml? I tried with Qt.WindowActive in the timers but doesnt works
    someone knows how to do this?



  • me too facing this problem


  • Moderators



  • Thanks Eddy, but no, not helps, [myobject]= Qt.application.active ? “true” : “false”; only works if you have QtQuick 1.1, in Symbian^3/Anna doesnt work it. and this QEvent::ApplicationActivated QEvent::ApplicationDeactivate .... I dont know how to use it, I dont know nothing about c++, im experimenting about this but an example works in windows but when I try it on my phone only apears a black screen. this is the example:

    @
    // MyApp.h

    #include <QtGui/QApplication>
    #include <QEvent>
    #include <QtDebug>

    class MyApp : public QApplication
    {
    Q_OBJECT

    public:
    MyApp( int argc, char * argv[] )
    : QApplication( argc, argv )
    {}

    bool event( QEvent * pEvent )
    {
    if ( pEvent->type() == QEvent::ApplicationActivate )
    qDebug() << "ApplicationActivate";
    else if ( pEvent->type() == QEvent::ApplicationDeactivate )
    qDebug() << "ApplicationDeactivate";
    return QApplication::event( pEvent );
    }
    };

    // main.cpp

    #include "MyApp.h"
    #include <QWidget>

    int main(int argc, char *argv[])
    {
    MyApp a(argc, argv);
    QWidget w;
    w.show();
    return a.exec();
    }
    @

    in this page I found the code: http://www.qtcentre.org/archive/index.php/t-42679.html?s=e19b8566696c5326a76917c895349f2f

    I dont know how to connect this to my timers in my qml file :(
    someone knows something about this?

    [EDIT: code formatting (please wrap in @-tags), fixed link, Volker]



  • I don't know a solution for your actual problem, but the constructor of your MyApplication class is seriously broken. The constructor takes a reference to an int, not a copy:

    @
    // WRONG!
    MyApp( int argc, char * argv[] );

    // correct:
    MyApp( int &argc, char **argv );
    @

    char *argv[] and char **argv are equivalent, but it's a good idea to use the very same signature than the base class.



  • thanks Volker, now Im investigating this code, at least it works when I put my phone into background, it send a message to the pc:
    MyApp.h:
    @
    #include <QDebug>

    #ifdef Q_OS_SYMBIAN
    #include <QSymbianEvent>
    #include <w32std.h>
    #endif

    class MyApplication : public QApplication
    {
    public:
    MyApplication( int argc, char** argv ) : QApplication( argc, argv ) {}

    #ifdef Q_OS_SYMBIAN
    protected:
    bool symbianEventFilter( const QSymbianEvent* symbianEvent ) {
    const TWsEvent *event = symbianEvent->windowServerEvent();

      if( !event ) {
        return false;
      }
    
      switch( event->Type() ) {
        case EEventFocusGained: {
          qDebug() << "Focus gained";
          break;
        }
        case EEventFocusLost: {
          qDebug() << "Focus lost";
          break;
        }
        default:
          break;
      }
    
      // Always return false so we don't stop
      // the event from being processed
      return false;
    }
    

    #endif // Q_OS_SYMBIAN
    };
    @
    and in main.cpp:
    @
    #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"
    #include "MyApp.h"
    #include <QWidget>

    int main(int argc, char *argv[])
    {
    MyApp a(argc, argv);
    QWidget w;
    w.show();
    return a.exec();
    }
    @

    the qml for the example is simple:
    main.qml:
    @
    import QtQuick 1.0

    Rectangle {
    id: rec
    width: 360
    height: 360
    property int tiempo: 0

    Text {
        text: rec.tiempo
        anchors.centerIn: parent
    }
    Timer{
        id: time
        interval: 1000
        repeat: true
        running:true
        onTriggered: rec.tiempo+=1
    }
    

    }
    @
    now I dont kwon how I send a signal to the qml file, I dont know a lot of c++, how I send this signal to my timer to stop it?
    thanks

    I see the code here: http://www.developer.nokia.com/Community/Wiki/TSQ001585_-Detecting_focus_lost&_gained_events_in_Qt_for_Symbian



  • Please change your constructor:

    @
    // still WRONG:
    MyApplication( int argc, char** argv )

    // correct:
    MyApplication( int &argc, char** argv )

    // it's int &argc
    // not int argc
    @



  • sorry Volker now it´s ok, I think, at least it works:
    MyApp.h:
    @
    #include <QDebug>

    #ifdef Q_OS_SYMBIAN
    #include <QSymbianEvent>
    #include <w32std.h>
    #endif

    class MyApp : public QApplication
    {
    public:
    MyApp( int &argc, char** argv ) : QApplication( argc, argv ) {}

    #ifdef Q_OS_SYMBIAN
    protected:
    bool symbianEventFilter( const QSymbianEvent* symbianEvent ) {
    const TWsEvent *event = symbianEvent->windowServerEvent();

      if( !event ) {
        return false;
      }
    
      switch( event->Type() ) {
        case EEventFocusGained: {
          qDebug() << "Focus gained";
          break;
        }
        case EEventFocusLost: {
          qDebug() << "Focus lost";
          break;
        }
        default:
          break;
      }
    
      // Always return false so we don't stop
      // the event from being processed
      return false;
    }
    

    #endif // Q_OS_SYMBIAN
    };
    @
    main.cpp:
    @
    #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"
    #include "MyApp.h"
    #include <QWidget>

    int main(int argc, char *argv[])
    {
    MyApp a(argc, argv);
    QWidget w;
    w.show();
    return a.exec();
    }
    @
    and the main.qml:
    @
    import QtQuick 1.0

    Rectangle {
    id: rec
    width: 360
    height: 360
    property int tiempo: 0

    Text {
        text: rec.tiempo
        anchors.centerIn: parent
    }
    Timer{
        id: time
        interval: 1000
        repeat: true
        running:true
        onTriggered: rec.tiempo+=1
    }
    

    }
    @

    now I want to put a property in main.qml that change when the MyApp.h change and I dont know how I do this, the code in the main.qml will be:
    @
    import QtQuick 1.0

    Rectangle {
    id: rec
    width: 360
    height: 360
    property int tiempo: 0
    property bool activo: true

    Text {
        text: rec.tiempo
        anchors.centerIn: parent
    }
    Timer{
        id: time
        interval: 1000
        repeat: true
        running:true
        onTriggered: [rec.tiempo+=1; activo()]
    }
    function activo(){
          if (rec.activo == true){ time.running=true}
          else if(rec.activo == false){ time.running = false}
    

    }
    @
    But I dont know how to change the property activo with the MyApp.h, I´m investigating this, but C++ it´s a bit more dificult to me than java.
    thanks for the help.



  • I solved this:

    for Symbian^3 or anna:

    only you have to put this:

    create a property bool pausemode like this:

    @property bool pausemode: (symbian.foreground? "false" : "true")@

    and in the same qml import this:
    @import com.nokia.symbian 1.1@

    when the phone enter in the background mode the property turns to true

    I created a timer like this in the game:

    @Timer{
    id: paused
    interval:10
    onTriggered: recto.state = "pause"
    running: main.pausemode
    }@

    it´s very simple but this problem took me 1 week giving me headaches.

    in belle:
    @property bool pausemode: (Qt.application.active? "false" : "true")@

    it´s very similar. it´s not necessary to import "com.nokia.symbian 1.1"

    one good solution for not make a lot of imports is to create a main.qml and a loader and in the main put the property and when you connect other qml (the game qml) and load it into the main only you have to put the timer in the game qml.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.