Results 1 to 10 of 10

Thread: A* pathfind algorithm and Grid

  1. #1
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default A* pathfind algorithm and Grid

    Hi i want to make some findpath app i am using QML and i don't know how to implement this because i don't know how makes node from QML grid. But i have some problems with implement algorithm. Can somebody give me some advices or links.
    Thanks

  2. #2
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* pathfind algorithm and Grid

    Any help? i simply don't know how to make from QML grid something like tree or graph and how to sent it to c++ class.

  3. #3
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A* pathfind algorithm and Grid

    How do you generate grid?

  4. #4
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: A* pathfind algorithm and Grid

    the best approach is to use GridView. Data model and A* algorithm I would implement in C++.

  5. #5
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* pathfind algorithm and Grid

    yes i will implement A* algorithm in C++ but have you some source or example ??? It will help me a lot
    Thanks for help

  6. #6
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A* pathfind algorithm and Grid

    What do you need example for?
    Try to subdivide your task to a series of simpler task, then you can easily google it/look it up in reference.

    1. How to implement A* in C++ (http://code.activestate.com/recipes/...ath-algorithm/).
    2. How to expose C++ classes to QML (http://qt-project.org/doc/qt-5.0/qtq...ttributes.html).
    3. How to dynamically generate QML elements (http://kunalmaemo.blogspot.ru/2011/0...ically-on.html).

  7. #7
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* pathfind algorithm and Grid

    I want some example how to use A* algorithm with QML GridLayout

  8. #8
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A* pathfind algorithm and Grid

    OK, I don't think there's particular example or specific component in qt for that.
    Try to do it yourself, start with simple QML - C++ calls, then implement graph structure in QML (for example add to your node objects references to neighbors).
    Then you can expose these elements to C++, or you can serialize them and send to C++.
    After calculating shortest path you can return it as a list of identifiers for example.

    Be creative, every complex task is just a number of simple tasks, don't be afraid to write some code!

  9. #9
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* pathfind algorithm and Grid

    Hi yesterday i start code and i do this but i dont know what with walls i dont know how to go back i somebody will look my code and help me i will happy
    Code: A-StarTest01.zip

  10. #10
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* pathfind algorithm and Grid

    ok i make it otherwise :
    Qt Code:
    1. pathFind = false;
    2. openList.clear();
    3. QQuickItem *currentItem = start;
    4. QList<QQuickItem*> path;
    5. openList.append(start);
    6. while(!openList.isEmpty())
    7. {
    8. findNeighbors(currentItem);
    9.  
    10. QQuickItem *minimal = openList.first();
    11. foreach (QQuickItem *item, openList)
    12. {
    13. int minF = getF(currentItem, minimal);
    14. int itemF = getF(currentItem, item);
    15. if(itemF < minF)
    16. {
    17. minimal = item;
    18.  
    19. }
    20. }
    21. openList.removeOne(start);
    22. closedList.append(currentItem);
    23. currentItem = minimal;
    24. path.append(currentItem);
    25. if(currentItem == finish)
    26. {
    27. pathFind = true;
    28. drawPath(path);
    29. }
    30. }
    31. qDebug() << (pathFind ? "path finded" : "no path");
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    but this algorthm dont know how go back

Similar Threads

  1. Help to set up sorting algorithm
    By Quasar in forum General Programming
    Replies: 2
    Last Post: 12th June 2012, 00:16
  2. No Response when Algorithm runs...
    By revellix in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2011, 17:24
  3. qt algorithm speed up problem
    By leonardhead in forum Newbie
    Replies: 3
    Last Post: 27th August 2010, 01:03
  4. qtthread to speed up the algorithm
    By leonardhead in forum Qt Programming
    Replies: 1
    Last Post: 20th August 2010, 05:09
  5. Dijkstra's Algorithm
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2006, 10:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.