PDA

View Full Version : Qt Creat or crashes when QPrinter object is declared



fredykhan
18th February 2011, 15:49
Hello,

I am using QT 4.6.3. When I create an object of QPrinter (i.e QPrinter printer()),
Qt Creator crashes at this declaration. I debuged to this statement and as i press F10 to execute this statement gdb crashes with error " gdb.exe (process id 4063) crashed"

I would appreciate a prompt response in this regard.

Thank You

high_flyer
18th February 2011, 16:02
Please post the full method where this line is in.

fredykhan
18th February 2011, 16:06
Here is my code....the debuger crashes on the QPrinter printer decleration

void mainScreen::printreport()
{
QSqlTableModel *model;
QPrinter printer;
model = new QSqlTableModel(this);
model->setTable("instreportview");
model->select();
QString dir = QFileDialog::getExistingDirectory(this, tr("Folder to store report in"),
"/home",
QFileDialog::ShowDirsOnly);
// | QFileDialog::DontResolveSymlinks);
checkdialog=false;
userprompt = new QDialog(this);
QString note="Please enter below the file name by which you want to save the report.";
note+=" The report will be saved on the desktop";
QLabel *userinfo=new QLabel(this);
userinfo->setText(note);
//QLabel *directory
QLabel *fnamelabel= new QLabel(tr("File Name"));
fname= new QLineEdit(this);
QPushButton *_cancelInfo = new QPushButton(tr("&Cancel"));
QPushButton *_saveInfo = new QPushButton(tr("&Save"));
QVBoxLayout *buttonlay = new QVBoxLayout(this);
QVBoxLayout *leftlay = new QVBoxLayout(this);
QHBoxLayout *labellay = new QHBoxLayout(this);
QHBoxLayout *mainlay = new QHBoxLayout(this);
_cancelInfo->setDefault(true);
_saveInfo->setDefault(true);
buttonlay->addWidget(_cancelInfo);
buttonlay->addWidget(_saveInfo);

labellay->addWidget(fnamelabel);
labellay->addWidget(fname);

//leftlay->addWidget(userinfo);
//leftlay->addLayout(labellay);

mainlay->addLayout(labellay);
mainlay->addLayout(buttonlay);

userprompt->setLayout(mainlay);
connect(_cancelInfo,SIGNAL(clicked()),this,SLOT(di alogcancel()));
connect(_saveInfo,SIGNAL(clicked()),this,SLOT(dial ogsave()));
userprompt->exec();
QString filename=fname->text();

QFont head1;
head1.setBold(true);
head1.setPixelSize(18);
QString heading;//=head.bold();
heading=" Bank Relationship Management System";
QTextCharFormat charformat;
charformat.setFont(head1);
charformat.setVerticalAlignment(QTextCharFormat::A lignMiddle);
doc=new QTextDocument();

cursor= new QTextCursor(doc);
cursor->movePosition(QTextCursor::WordRight,QTextCursor::M oveAnchor,2);
cursor->insertText(heading,charformat);
cursor->movePosition(QTextCursor::Down,QTextCursor::MoveAn chor,2);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(5);
tableFormat.setHeaderRowCount(1);
tableFormat.setBorderStyle(
QTextFrameFormat::BorderStyle_Solid);
tableFormat.setWidth(QTextLength(
QTextLength::PercentageLength, 100));
int rows=model->rowCount();
int cols=model->columnCount();
cursor->insertTable(rows,cols,tableFormat);

cursor->insertText(QObject::tr("Instrument Number"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Bank"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Branch"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Second Party"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Type"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Sub Type"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Status"));
cursor->movePosition(QTextCursor::NextCell);
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Amount"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Local Comptuted Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Computed Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Negotiated Cost"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Currency"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Opening Date"));
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(QObject::tr("Closing Date"));

QTextTable *table = cursor->currentTable();
for(int i=0;i<model->rowCount();i++)
{

table->appendRows(1);
//cursor->movePosition(QTextCursor::PreviousRow);
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(0).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(1).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(2).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(3).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(4).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(5).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(6).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(7).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(8).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(9).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(10).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(11).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(12).toString());
cursor->movePosition(QTextCursor::NextCell);
cursor->insertText(model->record(i).value(13).toString());
}

doc->setMetaInformation(QTextDocument::DocumentTitle,he ading);

printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOrientation(QPrinter::Landscape);
printer.setPaperSize(QPrinter::A4);
//printer.setResolution(QPrinter::HighResolution);
QString fpathname="C:/Documents and Settings/fredy/Desktop/";
QString fullname= dir+filename+".pdf";
printer.setOutputFileName(fullname);
QPainter painter;

QRectF rect=QRectF();
rect.setWidth(printer.width());//doc->textWidth());
rect.setHeight(printer.height());
if (! painter.begin(&printer)) { // failed to open file
qWarning("failed to open file, is it writable?");
//return 1;
}
else
{
if(checkdialog==true)
{
doc->drawContents(&painter, rect);
QString mess="Report Saved!";
QMessageBox msg(this);
msg.setText(mess);
msg.exec();
checkdialog=false;
}


}
painter.end();

}

high_flyer
18th February 2011, 16:16
you mean the line 4 in the code above?

fredykhan
18th February 2011, 16:21
yes the line 4 and i know it sounds stupid :)

high_flyer
18th February 2011, 16:24
What happens if you put a debug statement, and run application directly, without stepping through?

fredykhan
18th February 2011, 17:34
can you briefly describe what do u mean by debug statement. do u mean break point or something else.

wysota
18th February 2011, 18:00
Hello,

I am using QT 4.6.3. When I create an object of QPrinter (i.e QPrinter printer()),
Qt Creator crashes at this declaration. I debuged to this statement and as i press F10 to execute this statement gdb crashes with error " gdb.exe (process id 4063) crashed"

I would appreciate a prompt response in this regard.



QPrinter printer();
This is a declaration of a function called "printer" that takes no parameters and returns a QPrinter object and not a declaration of a QPrinter instance called "printer". Try to be explicit when you say something :)

Also does QtCreator crash or does your app crash?

high_flyer
18th February 2011, 18:02
But wysota, look at his code, he is calling it so:

QPrinter printer;

wysota
18th February 2011, 18:04
I know, it's just in the first post he said it was "QPrinter printer()".

fredykhan
18th February 2011, 18:15
sorry for my mistake actually I ment "QPrinter printer;" . wysota my app does not crash nor does my QT creator. Actually this is the function to print a report. If i am running the program and click the button that calls this function, everything works fine but no report is created. So, when i debug to this line, the gdb crashes Here
i get the error. "The application "gdb.exe" (process id 3088) crashed. Would you like to debug?"

wysota
18th February 2011, 18:25
So why are you posting this problem here and not on some gdb forum?

fredykhan
18th February 2011, 18:36
because it is happening on QPrinter object decleration and nowhere else :)

wysota
18th February 2011, 18:44
because it is happening on QPrinter object decleration and nowhere else :)

Tough luck, still we can't help you with this. Try debugging the debugger and see where it crashes :]