Results 1 to 3 of 3

Thread: Dijkstra's Algorithm

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Dijkstra's Algorithm

    hey there im trying to implement Dijkstar's algorithm with QPainter. ive managed to create the nodes which get placed on the QPainter and i have created arrows to link the nodes together but the links i used are created using drawLine using an array to store the points and dont really link the nodes properly. i also tried using QInputDialog to get the integer value for the distance between the nodes but i get an error from debug mode saying "it is dangerous to leave painters active on a widget outside the QPaint event"

    is there any proper way to create the links so that i can call qinputdialog and obtain distances between the links.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dijkstra's Algorithm

    I think you are doing the painting in the wrong place. You should do that in the paint event. And you should fetch the data earlier.

  3. #3
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Dijkstra's Algorithm

    Create a data structure which represents your problem, and then paint it.

    General solution for graphs: create a node object, create a map, which has as key a pair of nodes (the edges), and then the nodes. (Using the STL, this would be map<pair<Node *, Node *>, Node *>).
    In the Node object, add a draw method, then create a method for drawing edges in the graph class, in addition to a method that calls the draw method of the nodes and method for the edges.

Similar Threads

  1. Easy algorithm to encrypt / decrypt string data?
    By Mike in forum Qt Programming
    Replies: 7
    Last Post: 2nd March 2006, 06:42

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.