它是一个 Qt 应用程序,但没有 Gui。我正在尝试使用 GraphViz C++ 库创建一个图形。一切都运行良好,只是我无法获得可以在 Windows 中打开的 .png 文件中的输出。我按照手册说的做了,没有错误只是没有生成输出文件。我搜索了所有可能的目录但徒劳无功。请指导我。
gw.h 头文件
#ifndef GW_H
#define GW_H
#include <QApplication>
#include <QDebug>
#include "gvc.h"
#include <iostream>
#include <map>
using namespace std;
struct Node
{
NODES() {}
Agnode_t* actualNode;
char* name;
};
class GRAPHVIZ_WRAPPER {
public:
GVC_t* graphContext;
Agraph_t* graph;
map <char*,Agnode_t*> nodesTable;
GRAPHVIZ_WRAPPER(int x)
{
graphContext = gvContext();
graph = agopen("Node Graph" , Agdirected , NULL);
}
void addNode(char* lable)
{
qDebug("Adding Node");
Agnode_t* node = agnode(graph,lable,TRUE);
nodesTable.insert(pair<char*,Agnode_t*>(lable,node));
}
void addEdge(char* node1 , char* node2, char* lable)
{
qDebug("Adding Edge");
Agnode_t* tailNode = nodesTable[node1];
Agnode_t* headNode = nodesTable[node2];
agedge(graph,tailNode,headNode,lable,TRUE);
}
void draw()
{
gvLayout(graphContext,graph,"dot");
gvRenderFilename(graphContext,graph,"png","QwertyGrap.pngh");
gvFreeLayout(graphContext,graph);
}
void close()
{
agclose(graph);
}
};
#endif // GW_H
Main.cpp 文件
#include "gw.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// MainWindow w;
//w.show();
//w.drawGraph();
GRAPHVIZ_WRAPPER Mgraph(5);
Mgraph.addNode("Node1");
Mgraph.addNode("Node2");
Mgraph.addNode("Node3");
Mgraph.addEdge("Node1","Node2","76");
Mgraph.addEdge("Node1","Node3","86");
Mgraph.addEdge("Node2","Node1","96");
Mgraph.draw();
qDebug("Drawing");
Mgraph.close();
return a.exec();
}
输出(如您所见程序正在运行且没有错误)