Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] Pause mode doesn´t work

[Solved] Pause mode doesn´t work

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 4 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tommyj23
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mismail
      wrote on last edited by
      #2

      me too facing this problem

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        Maybe "this post":http://developer.qt.nokia.com/forums/viewthread/10084 helps.

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tommyj23
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tommyj23
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Please change your constructor:

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

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

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

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tommyj23
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tommyj23
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved