Results 1 to 14 of 14

Thread: Qt Creat or crashes when QPrinter object is declared

  1. #1
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Qt Creat or crashes when QPrinter object is declared

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Creat or crashes when QPrinter object is declared

    Please post the full method where this line is in.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Creat or crashes when QPrinter object is declared

    Here is my code....the debuger crashes on the QPrinter printer decleration
    Qt Code:
    1. void mainScreen::printreport()
    2. {
    3. QPrinter printer;
    4. model = new QSqlTableModel(this);
    5. model->setTable("instreportview");
    6. model->select();
    7. QString dir = QFileDialog::getExistingDirectory(this, tr("Folder to store report in"),
    8. "/home",
    9. QFileDialog::ShowDirsOnly);
    10. // | QFileDialog::DontResolveSymlinks);
    11. checkdialog=false;
    12. userprompt = new QDialog(this);
    13. QString note="Please enter below the file name by which you want to save the report.";
    14. note+=" The report will be saved on the desktop";
    15. QLabel *userinfo=new QLabel(this);
    16. userinfo->setText(note);
    17. //QLabel *directory
    18. QLabel *fnamelabel= new QLabel(tr("File Name"));
    19. fname= new QLineEdit(this);
    20. QPushButton *_cancelInfo = new QPushButton(tr("&Cancel"));
    21. QPushButton *_saveInfo = new QPushButton(tr("&Save"));
    22. QVBoxLayout *buttonlay = new QVBoxLayout(this);
    23. QVBoxLayout *leftlay = new QVBoxLayout(this);
    24. QHBoxLayout *labellay = new QHBoxLayout(this);
    25. QHBoxLayout *mainlay = new QHBoxLayout(this);
    26. _cancelInfo->setDefault(true);
    27. _saveInfo->setDefault(true);
    28. buttonlay->addWidget(_cancelInfo);
    29. buttonlay->addWidget(_saveInfo);
    30.  
    31. labellay->addWidget(fnamelabel);
    32. labellay->addWidget(fname);
    33.  
    34. //leftlay->addWidget(userinfo);
    35. //leftlay->addLayout(labellay);
    36.  
    37. mainlay->addLayout(labellay);
    38. mainlay->addLayout(buttonlay);
    39.  
    40. userprompt->setLayout(mainlay);
    41. connect(_cancelInfo,SIGNAL(clicked()),this,SLOT(dialogcancel()));
    42. connect(_saveInfo,SIGNAL(clicked()),this,SLOT(dialogsave()));
    43. userprompt->exec();
    44. QString filename=fname->text();
    45.  
    46. QFont head1;
    47. head1.setBold(true);
    48. head1.setPixelSize(18);
    49. QString heading;//=head.bold();
    50. heading=" Bank Relationship Management System";
    51. QTextCharFormat charformat;
    52. charformat.setFont(head1);
    53. charformat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
    54. doc=new QTextDocument();
    55.  
    56. cursor= new QTextCursor(doc);
    57. cursor->movePosition(QTextCursor::WordRight,QTextCursor::MoveAnchor,2);
    58. cursor->insertText(heading,charformat);
    59. cursor->movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,2);
    60. QTextTableFormat tableFormat;
    61. tableFormat.setCellPadding(5);
    62. tableFormat.setHeaderRowCount(1);
    63. tableFormat.setBorderStyle(
    64. QTextFrameFormat::BorderStyle_Solid);
    65. tableFormat.setWidth(QTextLength(
    66. QTextLength::PercentageLength, 100));
    67. int rows=model->rowCount();
    68. int cols=model->columnCount();
    69. cursor->insertTable(rows,cols,tableFormat);
    70.  
    71. cursor->insertText(QObject::tr("Instrument Number"));
    72. cursor->movePosition(QTextCursor::NextCell);
    73. cursor->insertText(QObject::tr("Opening Bank"));
    74. cursor->movePosition(QTextCursor::NextCell);
    75. cursor->insertText(QObject::tr("Opening Branch"));
    76. cursor->movePosition(QTextCursor::NextCell);
    77. cursor->insertText(QObject::tr("Second Party"));
    78. cursor->movePosition(QTextCursor::NextCell);
    79. cursor->insertText(QObject::tr("Type"));
    80. cursor->movePosition(QTextCursor::NextCell);
    81. cursor->insertText(QObject::tr("Sub Type"));
    82. cursor->movePosition(QTextCursor::NextCell);
    83. cursor->insertText(QObject::tr("Status"));
    84. cursor->movePosition(QTextCursor::NextCell);
    85. cursor->movePosition(QTextCursor::NextCell);
    86. cursor->insertText(QObject::tr("Amount"));
    87. cursor->movePosition(QTextCursor::NextCell);
    88. cursor->insertText(QObject::tr("Local Comptuted Cost"));
    89. cursor->movePosition(QTextCursor::NextCell);
    90. cursor->insertText(QObject::tr("Computed Cost"));
    91. cursor->movePosition(QTextCursor::NextCell);
    92. cursor->insertText(QObject::tr("Negotiated Cost"));
    93. cursor->movePosition(QTextCursor::NextCell);
    94. cursor->insertText(QObject::tr("Currency"));
    95. cursor->movePosition(QTextCursor::NextCell);
    96. cursor->insertText(QObject::tr("Opening Date"));
    97. cursor->movePosition(QTextCursor::NextCell);
    98. cursor->insertText(QObject::tr("Closing Date"));
    99.  
    100. QTextTable *table = cursor->currentTable();
    101. for(int i=0;i<model->rowCount();i++)
    102. {
    103.  
    104. table->appendRows(1);
    105. //cursor->movePosition(QTextCursor::PreviousRow);
    106. cursor->movePosition(QTextCursor::NextCell);
    107. cursor->insertText(model->record(i).value(0).toString());
    108. cursor->movePosition(QTextCursor::NextCell);
    109. cursor->insertText(model->record(i).value(1).toString());
    110. cursor->movePosition(QTextCursor::NextCell);
    111. cursor->insertText(model->record(i).value(2).toString());
    112. cursor->movePosition(QTextCursor::NextCell);
    113. cursor->insertText(model->record(i).value(3).toString());
    114. cursor->movePosition(QTextCursor::NextCell);
    115. cursor->insertText(model->record(i).value(4).toString());
    116. cursor->movePosition(QTextCursor::NextCell);
    117. cursor->insertText(model->record(i).value(5).toString());
    118. cursor->movePosition(QTextCursor::NextCell);
    119. cursor->insertText(model->record(i).value(6).toString());
    120. cursor->movePosition(QTextCursor::NextCell);
    121. cursor->insertText(model->record(i).value(7).toString());
    122. cursor->movePosition(QTextCursor::NextCell);
    123. cursor->insertText(model->record(i).value(8).toString());
    124. cursor->movePosition(QTextCursor::NextCell);
    125. cursor->insertText(model->record(i).value(9).toString());
    126. cursor->movePosition(QTextCursor::NextCell);
    127. cursor->insertText(model->record(i).value(10).toString());
    128. cursor->movePosition(QTextCursor::NextCell);
    129. cursor->insertText(model->record(i).value(11).toString());
    130. cursor->movePosition(QTextCursor::NextCell);
    131. cursor->insertText(model->record(i).value(12).toString());
    132. cursor->movePosition(QTextCursor::NextCell);
    133. cursor->insertText(model->record(i).value(13).toString());
    134. }
    135.  
    136. doc->setMetaInformation(QTextDocument::DocumentTitle,heading);
    137.  
    138. printer.setOutputFormat(QPrinter::PdfFormat);
    139. printer.setOrientation(QPrinter::Landscape);
    140. printer.setPaperSize(QPrinter::A4);
    141. //printer.setResolution(QPrinter::HighResolution);
    142. QString fpathname="C:/Documents and Settings/fredy/Desktop/";
    143. QString fullname= dir+filename+".pdf";
    144. printer.setOutputFileName(fullname);
    145. QPainter painter;
    146.  
    147. QRectF rect=QRectF();
    148. rect.setWidth(printer.width());//doc->textWidth());
    149. rect.setHeight(printer.height());
    150. if (! painter.begin(&printer)) { // failed to open file
    151. qWarning("failed to open file, is it writable?");
    152. //return 1;
    153. }
    154. else
    155. {
    156. if(checkdialog==true)
    157. {
    158. doc->drawContents(&painter, rect);
    159. QString mess="Report Saved!";
    160. QMessageBox msg(this);
    161. msg.setText(mess);
    162. msg.exec();
    163. checkdialog=false;
    164. }
    165.  
    166.  
    167. }
    168. painter.end();
    169.  
    170. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 18th February 2011 at 16:14. Reason: code tags

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Creat or crashes when QPrinter object is declared

    you mean the line 4 in the code above?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Creat or crashes when QPrinter object is declared

    yes the line 4 and i know it sounds stupid

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Creat or crashes when QPrinter object is declared

    What happens if you put a debug statement, and run application directly, without stepping through?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Creat or crashes when QPrinter object is declared

    can you briefly describe what do u mean by debug statement. do u mean break point or something else.

  8. #8
    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: Qt Creat or crashes when QPrinter object is declared

    Quote Originally Posted by fredykhan View Post
    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.
    Qt Code:
    1. QPrinter printer();
    To copy to clipboard, switch view to plain text mode 
    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?
    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.


  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Creat or crashes when QPrinter object is declared

    But wysota, look at his code, he is calling it so:
    Qt Code:
    1. QPrinter printer;
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    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: Qt Creat or crashes when QPrinter object is declared

    I know, it's just in the first post he said it was "QPrinter printer()".
    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.


  11. #11
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Creat or crashes when QPrinter object is declared

    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?"

  12. #12
    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: Qt Creat or crashes when QPrinter object is declared

    So why are you posting this problem here and not on some gdb forum?
    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.


  13. #13
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt Creat or crashes when QPrinter object is declared

    because it is happening on QPrinter object decleration and nowhere else

  14. #14
    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: Qt Creat or crashes when QPrinter object is declared

    Quote Originally Posted by fredykhan View Post
    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 :]
    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. beginInsertRows was not declared ???
    By travlr in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2009, 21:22
  2. 'XEvent' has not been declared
    By dacla in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 31st March 2008, 12:44
  3. How to creat different shape of pushbutton?
    By Manohar in forum Qt Tools
    Replies: 16
    Last Post: 28th March 2008, 14:16
  4. qmake creat Makefile.Debug has error
    By freegnu in forum Qt Programming
    Replies: 4
    Last Post: 12th June 2006, 07:31
  5. QPrinter::PrinterMode and QPrinter::setResolution??
    By SkripT in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2006, 11:59

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.