@
@
@binarSun2020-10-23 05:45:28
Qt
@binarSun, 2020-10-23 05:45:28

When connecting GraphViz to a project in QT, a picture with a graph is not created. I read the documentation. The .dot file appears, but the .png does not. Why?

void MainWindow::on_pushButton_6_clicked()
{
    bool ok = true;
    QString matrix = "", draw = "";
    if(ui->radioButton->isChecked()) draw += "digraph G{\n";
        else draw += "graph G{\n";
    QString spacer = "";
    if(ui->radioButton->isChecked()) spacer += "->";
        else spacer += "--";
    draw += globalNodesDraw;
    n = ui->table_i->rowCount();
    m = ui->table_i->columnCount();

    for (int i = 0; i < n; ++i)//заполняем таблицу инцидентности
    {
        for (int j = 0; j < m; ++j)
        {
            QString one = ui->table_i->item(i,j)->text();//берём элемент матрицы
            int cur = one.toInt(&ok,10);
            imatrix[i][j] = cur;
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
            for(int k = 0; k<imatrix[i][j]; k++) draw += "X" + QString::number(i+1) + spacer + "X" + QString::number(j+1) + ";\n";
    }
    draw += "}";
    QString fileName = QDir::currentPath() + "\\buffer.dot";
    QFile file(fileName);
    if ( file.open(QIODevice::ReadWrite) )
    {
        file.resize(0);
        QTextStream stream( &file );
        stream << draw << endl;
    }
        QString currentPath = QDir::currentPath();
        currentPath.replace("/", "\\");
        QString commandStr = "\"C:\\Program\" \"Files\" (x86)\\Graphviz\\bin\\dot.exe\" \"-Tpng\" \""+ currentPath +"\\buffer.dot\" \"-o\" \""+ currentPath +"~/""\\output.png\"";
        QByteArray commandChar = commandStr.toLocal8Bit();
        const char *command = commandChar.data();
        system(command);
        QString pathToImage = QDir::currentPath() + "\\output.png";
        QPixmap pixmap(pathToImage);
        QGraphicsScene scene;
        scene.addPixmap(QPixmap(pathToImage));
        ui->graphicsView->setScene(&scene);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question