Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Split] QApplication subclassing problem
Forum Updated to NodeBB v4.3 + New Features

[Split] QApplication subclassing problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.8k Views 1 Watching
  • 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
    Tratstil
    wrote on last edited by
    #1

    [Moderator's note: I've split off this topic from the "original thread":http://developer.qt.nokia.com/forums/viewthread/9098, as it is a different problem, Volker]

    i have a class named qtgame which extends QApplication and has a function "init" to create some phonon::MediaObject. phonon::MediaObject needs application name to run correctly so I do it on main function.

    @
    int main(int argc, char *argv[])
    {
    qtgame _qtgame(argc,argv);
    _qtgame.setOrganizationName(ORGANIZATION_NAME);
    _qtgame.setOrganizationDomain(ORGANIZATION_DOMAIN);
    _qtgame.setApplicationName(APPLICATION_NAME);
    _qtgame.start();
    return _qtgame.exec();
    }
    @
    but phonon::MediaObject didn't run correctly. after that I have moved

    @
    _qtgame.setOrganizationName(ORGANIZATION_NAME);
    _qtgame.setOrganizationDomain(ORGANIZATION_DOMAIN);
    _qtgame.setApplicationName(APPLICATION_NAME);
    @
    to qtgame constructor like this
    @
    qtgame::qtgame(int argc, char *argv[]):QApplication(argc,argv){
    setOrganizationName(ORGANIZATION_NAME);
    setOrganizationDomain(ORGANIZATION_DOMAIN);
    setApplicationName(APPLICATION_NAME);
    init();
    }
    @
    the sound works good but when i paused game by sweeping screen to home screen, then i resumed game it crash. I showed the log file (i write something when the game running) and get some thing like that.

    but now it's ok, after changing some codes. Thanks for viewing.

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

      You must have argc as a reference, not as a value to the constructor. See "this forum post":http://developer.qt.nokia.com/forums/viewreply/21990/ for an explanation.

      The respective constructor of QApplication is:

      @
      QApplication ( int &argc, char **argv );
      @

      Change your constructor like this:

      @
      // WRONG version:
      qtgame(int argc, char *argv[]);

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

      Also, in your first version, where do you call init()? I cannot see a call to that function...

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tratstil
        wrote on last edited by
        #3

        thanks for replying
        but i think *argv[] === **argv :), i created a new project and Qt Creator made template code like this
        @
        int main(int argc, char *argv[])
        {
        QApplication app(argc, argv);

        QmlApplicationViewer viewer;
        viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
        viewer.setMainQmlFile(QLatin1String("qml/abc/main.qml"));
        viewer.showExpanded();
        
        return app.exec();
        

        }
        @
        so it is not problem.

        I put init() in qtgame constructor in my first version.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          char *argv[] is not the problem, int argc is.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tratstil
            wrote on last edited by
            #5

            :D oh my mistake, thanks all

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

              [quote author="Tratstil" date="1314177630"]
              I put init() in qtgame constructor in my first version.[/quote]

              Then it is crystal clear why it does not work:
              You call setOrganizationName() and the others after the constructor of qtgame has finished. So, your init() method is called in the constructor just before the names have been set.

              BTW:
              You should consider to not "abuse" QApplication for your purposes. For me it looks a bit odd, and I would create a specialized object for the phonon stuff.

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

              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