Important: Please read the Qt Code of Conduct -

Dynamic Object Management (Create, Delete, Create, ....)

  • Hello All,

    I am in process to build a game using Qt and C++ for Meego. I have come across a scenario in which a box2d word is created and game get started. After quitting game, user go to the main menu and then as he want to play a new game. As user presses new game button and 'gamePage' (which is actually a Rectangle Element) is displayed. In this page I have to place box2d world again with initialized bodies. but in my case bodies in box2d world are in previous positions.

    So what I want is that every time new game starts new world should be created and will be placed in 'gamePage'.

    I am using following box2d demo to build my game application ''

    I have used Loader and Component Elements but these didn't show required results.

    here are some code segments to give you more info about the matter.


    MouseArea {
    anchors.fill : parent

    onPressed: {
    newGameImage.source = "menu_item_h.jpg"

    onReleased: {
    newGameImage.source = "menu_item.jpg"

    onClicked: {
    newGameImage.source = "menu_item.jpg"

    mainPage.opacity = 0.0
    gamePage.opacity = 1.0


    above code segment is from file MainPage.qml

    following is from file GamePage.qml

    Component {
    id: worldComponent

    id: world
    objectName: "worldObject"

    width: worldWidth
    height: worldHeight

    Loader {
    id: worldLoader

    sourceComponent : worldComponent

    onLoaded: {
    console.log("World Loaded: "+ initCtrlElement)

    Kindly guide me.


    [edit: @ code tags added, Eddy]

Log in to reply