PDA

View Full Version : ASCII to PDF



jaca
18th September 2009, 00:03
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


#include <QDebug>
#include <QtGui>
#include <QFile>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <QPlainTextEdit>
#include <QPrinter>

int main(int argc, char **argv)
{

QDir currentDir;
QDir dirsList;
QDir saida;
QString line, textpdf;
QStringList files;
QStringList dirs;
QString pathDir = QString(argv[1]);
QString nomeDir = QString(argv[2]);
QString nomearq = QString(argv[3]);
QString arqsai = QString(argv[4]);
QPlainTextEdit *plainTexto = new QPlainTextEdit();
QPrinter printer;
printer.setPaperSize(QPrinter::A4);
printer.setOrientation(QPrinter::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);

dirsList = QDir(pathDir);
saida = QDir(arqsai);
dirs = dirsList.entryList(QStringList(nomeDir),
QDir::Dirs | QDir::NoSymLinks);
for(int i = 0; i < dirs.size(); ++i ){
currentDir = QDir(dirsList.absoluteFilePath(dirs[i]));
files = currentDir.entryList(QStringList(nomearq),
QDir::Files | QDir::NoSymLinks);
for(int i = 0; i < files.size(); ++i){
QFile file(currentDir.absoluteFilePath(files[i]));
printer.setOutputFileName(saida.absoluteFilePath(f iles[i]));
if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream in(&file);
while (!in.atEnd()) {
line = in.readLine();
line.append("\n");
textpdf += line;
}
}
file.close();
plainTexto->setPlainText(textpdf);
plainTexto->print(&printer);
}
}
return 0;
}

jaca
18th September 2009, 11:36
When I comment QPlainTextEdit and QPrinter the program does not display the error message.

jaca
19th September 2009, 22:27
:p QPlainTextEdit need QApplication.

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

wysota
19th September 2009, 23:51
Try using QTextDocument instead of QPlainTextEdit.