[Split] QApplication subclassing problem



  • [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.



  • 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...



  • 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.



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



  • :D oh my mistake, thanks all



  • [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.


Log in to reply
 

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