PDA

View Full Version : Dijkstra's Algorithm



therealjag
4th March 2006, 16:22
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.

wysota
4th March 2006, 18:11
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.

dublet
6th March 2006, 10:16
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.