@binarSun
Student, 18y.o.

При подключении GraphViz к проекту в QT не создается картинка с графом.Документацию читала. Файл .dot-появляется, а .png-нет. Почему?

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);
}
  • Вопрос задан
  • 101 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы