2017-01-17 14 views
0

私はアプリケーション用に2つのファイルを持っています。 1つはQJSONでデータファイルを保存し、もう1つはインクルードアプリの情報であるpdfです。Qt JSONとPDFファイルをパスに保存する

この2つのファイルをパスに保存したい(ユーザーが選択する)。ユーザーの選択ファイルのパスを取得するにはどうすればよいですか? Fallowing code blockには私のpdf saveメソッドとQJSONメソッドがあります。 - PDFを保存中です。他のクラスメソッドで

void MainWindow::saveAsPdf(){ 

    QString html= 
      "<!DOCTYPE html><html><body><b>Sample : </b><a>"+ui->sampleText->text()+"</a><br><b>Operator : </b> <a>"+ui->operatorText->text()+"</a><br><b>Method : </b> <a>"+ui->evalText->text()+" </a><br>"+ 
      "<b>Date : </b> <a>"+ui->date->text()+"</a><br><br>"+ 
      "<b>Mixer : </b> <a>300 </a>"+ 
      "<b>Moisture Content : </b> <a>"+ui->moistureText->text()+"</a><br>"+ 
      "<a>Consistency </a><b></b><a>with waterabsorption </a><a>"+ui->absorptionText->text()+"</a><br><br>"+ 
      "<b>Waterabsorption (correct for 500 FU) : </b> <a></a><br>"+ 
      "<b>Waterabsorption (correct for 14.0 %) : </b> <a></a><br>"+ 
      "<b>DevelopmentTime : </b> <a></a><br>"+ 
      "<b>Stability : </b> <a></a><br>"+ 
      "<b>Degree of Softening (10 min after begin) : </b> <a></a><br>"+ 
      "<b>Degree of Softening (ICC/ 12 min after max) : </b><a></a><br>"+ 
      "<b>Farinograph quality number : </b> <a></a><br>"+ 
      "<b>Remarks : </b><a>"+ui->remaskText->text()+"</a><br>"+ 
      "</body>"+ 
      "</html>"; 

    QTextDocument parent; 
    parent.setHtml(html); 
    QPrinter printer(QPrinter::HighResolution); 
    printer.setOutputFormat(QPrinter::PdfFormat); 
    printer.setColorMode(QPrinter::Color); 
    //printer.getPageMargins(*left); 
    printer.setOutputFileName(ui->operatorText->text()); 
    QPrintDialog*dlg = new QPrintDialog(&printer, this); 
    dlg->setWindowTitle(QObject::tr("Print Document")); 

    if(dlg->exec() == QDialog::Accepted) { 

     QPainter painter(&printer); 
     painter.drawPixmap(500, 5500, QPixmap(ui->qcustom->toPixmap(800,500,10.0))); 
     parent.setDefaultFont(QFont("Times", 200)); 
     parent.drawContents(&painter); 
     painter.end(); 

    } 
    delete dlg; 

}

-Saving JSONファイル、それだけでファイルパスを取得することです:

formula.savejson("/home/elif/Desktop/"+ui->operatorText->text()+".txt"); 

答えて

0

ユーザーがパスを選択したい場合は、QFileDialog::getExistingDirectory()を見て

関連する問題