Hello,
In code below I want to convert multiple files in ASCII format PDF. Do not want to use graphical interface. The compilation run ok. But when I run the program a message error is shown.
"Microsoft Visual C + + Runtime Library
This gas application requested the Runtime to terminate it in an unusual way. Plaese contact the application's support team for more information. "
Any idea? Thanks.
Qt 4.5
Qt Code:
  1. #include <QDebug>
  2. #include <QtGui>
  3. #include <QFile>
  4. #include <QDir>
  5. #include <QString>
  6. #include <QStringList>
  7. #include <QTextStream>
  8. #include <QPlainTextEdit>
  9. #include <QPrinter>
  10.  
  11. int main(int argc, char **argv)
  12. {
  13.  
  14. QDir currentDir;
  15. QDir dirsList;
  16. QDir saida;
  17. QString line, textpdf;
  18. QStringList files;
  19. QString pathDir = QString(argv[1]);
  20. QString nomeDir = QString(argv[2]);
  21. QString nomearq = QString(argv[3]);
  22. QString arqsai = QString(argv[4]);
  23. QPlainTextEdit *plainTexto = new QPlainTextEdit();
  24. QPrinter printer;
  25. printer.setPaperSize(QPrinter::A4);
  26. printer.setOrientation(QPrinter::Landscape);
  27. printer.setOutputFormat(QPrinter::PdfFormat);
  28.  
  29. dirsList = QDir(pathDir);
  30. saida = QDir(arqsai);
  31. dirs = dirsList.entryList(QStringList(nomeDir),
  32. QDir::Dirs | QDir::NoSymLinks);
  33. for(int i = 0; i < dirs.size(); ++i ){
  34. currentDir = QDir(dirsList.absoluteFilePath(dirs[i]));
  35. files = currentDir.entryList(QStringList(nomearq),
  36. QDir::Files | QDir::NoSymLinks);
  37. for(int i = 0; i < files.size(); ++i){
  38. QFile file(currentDir.absoluteFilePath(files[i]));
  39. printer.setOutputFileName(saida.absoluteFilePath(files[i]));
  40. if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
  41. QTextStream in(&file);
  42. while (!in.atEnd()) {
  43. line = in.readLine();
  44. line.append("\n");
  45. textpdf += line;
  46. }
  47. }
  48. file.close();
  49. plainTexto->setPlainText(textpdf);
  50. plainTexto->print(&printer);
  51. }
  52. }
  53. return 0;
  54. }
To copy to clipboard, switch view to plain text mode