Results 1 to 4 of 4

Thread: ASCII to PDF

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default ASCII to PDF

    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 

  2. #2
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ASCII to PDF

    When I comment QPlainTextEdit and QPrinter the program does not display the error message.

  3. #3
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ASCII to PDF

    QPlainTextEdit need QApplication.

    add
    #include <QApplication>
    ...
    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    ...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ASCII to PDF

    Try using QTextDocument instead of QPlainTextEdit.
    Last edited by wysota; 20th September 2009 at 00:57.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. get ASCII equivalent data
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 04:13
  2. Ascii control characters
    By priceey in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2009, 10:57
  3. How to Compare Characters ASCII value?
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 14th July 2008, 12:05
  4. Replies: 4
    Last Post: 10th July 2007, 20:11
  5. Howq to get the ascii of a char ?
    By yellowmat in forum Newbie
    Replies: 2
    Last Post: 27th April 2006, 21:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.