2013-06-08 1 views
0

편집 : 나는 컴파일 및 충돌없는 버전을 얻을 수있었습니다. 남아있는 유일한 것은 원하는 출력을 얻는 것입니다. 그러나이 특정 질문 (왜 충돌이 일어 났습니까?)이 응답되어 질문을 닫습니다. 나는 깨진 코드 앞에 작업 코드를 게시 할 것이다.QPrinter 런타임 오류

안녕하세요! 간단히 pdf 문서를 만드는 작은 예제를 만들려고합니다. 모든 것이 컴파일되지만 프로그램이 시작될 때 단순히 충돌합니다. 나는 Qt는 버전을 사용하고 5.0.0

--- 새로운 작업 코드 --- 여기

int main(int argc, char **argv) 
{ 
    QApplication app(argc, argv); 

    QTextDocument doc; 
    doc.setHtml("<p>A QTextDocument can be used to present formatted text " 
       "in a nice way.</p>" 
       "<p align=center>It can be <b>formatted</b> " 
       "<font size=+2>in</font> <i>different</i> ways.</p>" 
       "<p>The text can be really long and contain many " 
       "paragraphs. It is properly wrapped and such...</p>"); 
    QPrinter printer; 
    printer.setOutputFileName("C:\\Users\\SameTime\\Desktop\\Cutie\\PDFPrintMaybe"); 
    printer.setOutputFormat(QPrinter::PdfFormat); 
    doc.print(&printer); 
    printer.newPage(); 

    return 0; 
} 

프로젝트 코드 :

#------------------------------------------------- 
# 
# Project created by QtCreator 2013-06-08T10:07:11 
# 
#------------------------------------------------- 

QT  += core 

QT  -= gui 
QT += printsupport 
TARGET = PDFPrintMaybe 
CONFIG += console 
CONFIG -= app_bundle 

TEMPLATE = app 


SOURCES += main.cpp 

---- 오류 - 오래 코드

#include <QCoreApplication> 
#include <QTextDocument> 
#include <QPrinter> 


int main(int argc, char *argv[]) 
{ 
    QCoreApplication a(argc, argv); 
    QTextDocument doc; 
    doc.setHtml("<h1>Testing, testing, is this thing on?!</h1>"); 
    QPrinter printer; 
    printer.setOutputFileName("C:\\Users\\SameTime\\Desktop\\Cutie\\PDFPrintMaybe"); 
    printer.setOutputFormat(QPrinter::PdfFormat); 
    doc.print(&printer); 
    printer.newPage(); 
    return a.exec(); 
} 

가에서 컴파일하지만 (거의) 충돌하기 때문에 나는 손실에 조금입니다 : - 여기 그리고 메인 CPP입니다 끊임없이 달렸다.

+0

디버거에서 프로그램을 실행할 때 프로그램이 중단되는 위치는 어디입니까? –

+0

QTextDocument doc; 이 라인 – Bloodcount

+0

여전히 충돌, 나는 작업 버전을 얻을 수 있었다. (나는 여전히 원하는 출력을 얻지 못한다. 그러나 충돌은 없다.)이 스레드를 닫아야 하는가? – Bloodcount

답변

0

힙에 개체를 만들지 않으면 범위를 벗어 났을 때 자동으로 삭제됩니다. 그러면 프레임 워크가 해당 개체를 다시 삭제하려고 시도하고 충돌합니다.

QTextDocument *doc = new QTextDocument(); 
doc->setHtml("<h1>Testing, testing, is this thing on?!</h1>"); 
QPrinter* printer = new QPrinter(); 
printer->setOutputFileName("C:\\Users\\SameTime\\Desktop\\Cutie\\PDFPrintMaybe"); 
printer->setOutputFormat(QPrinter::PdfFormat); 
doc->print(printer); 
printer->newPage(); 
+0

포인터가 있어도 여전히 충돌이 발생합니다. – Bloodcount