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. QML and Qt handling Qobjects, QQuickItem
Forum Updated to NodeBB v4.3 + New Features

QML and Qt handling Qobjects, QQuickItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 130 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.
  • N Offline
    N Offline
    Naresh
    wrote on last edited by
    #1

    I am trying to make a game in qt and qml. I am including the most important part of the game. I have reduced it to simple form.

    Untitled Diagram.png

    n this game (above picture) there are 4 Boxes and two players (player1 and player2).

    1. In the first scenario player1 and 2 are both at rest place.

    2. In the second scenario player 1 moves to box 2 (assuming he gets 2 on dice ( generating random numbers) , this part is handled seperately and function will recieve the generated number only).

    3. In third scenario player 2 also gets 2 (assumption) so then player 2 moves to box 2 and player1 which was at box2 moves to rest place. ( all this is similar to Ludo, Snake ladder etc. games)

    The aim of this game is to see which player moves to box4 or beyond first wins the game.

    I can easily draw Box 1 to 4 in Qml and player 1 and 2. I can change the properties of these boxes in qt (c++) (using objectname from qml) via

    QQmlApplicationEngine engine;
    
    
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
    
    
    QObject *item = engine.rootObjects().first();
    
    
    auto child = item->findChild<QQuickItem*>("board");
    auto player1 = item->findChild<QQuickItem*>("player1");
    
    
    auto list = child->childItems();
    
    for (auto childItem: list )
    {
    
        if (childItem->objectName() == "Box2")
            QTimer::singleShot(2000, [player1,childItem,child]{
               player1->setProperty("x",childItem->property("x"));
               player1->setProperty("y",childItem->property("y"));
    
            });
    
    }
    

    But Issue with this approach is that it is too lengthy and every time i have to assign x and y value. I was hoping if we have a better approach in qt to handle such things (useful in scaling the game).

    Basically a great approach would be if somehow player1 can have same object as box2. So that they appear at same place and when player 2 comes and box2 position then player 1 can be moved to rest position.

    But the problem is that I am unable to do or perform it.

    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