Results 1 to 7 of 7

Thread: Printing problem in windows

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Printing problem in windows


    Hi,

    I am proting my application from qt3 to qt4 using Qt3Support.
    My Problem is , in my PRINTING CODE ( which was working both in WINDOWS && LINUX in Qt3 ) . Now after porting to Qt4 the same PRINTING CODE is CRASHING in WINDOWS...

    See the code below ....


    Qt Code:
    1. void ChemCanvas::printToPrinter( const RouteList *routeList )
    2. {
    3.  
    4.  
    5. // printer object
    6. #if (QT_VERSION < 0x030000)
    7. QPrinter printer;
    8. #else
    9. QPrinter printer( QPrinter::HighResolution );
    10.  
    11. #endif
    12. // original wcOrigin, saved to be restored after printing.
    13. QPoint originalWcOrigin = wcOrigin;
    14.  
    15. // With this set as true, objectNeedsRepainting won't
    16. // draw while scaling to printer canvas
    17. printing = TRUE;
    18.  
    19. // Set default printer characteristics to conform to the current
    20. // canvas settings.
    21. printer.setPageSize ( mappings.pageSize() );
    22. printer.setOrientation( mappings.orientation() );
    23. printer.setOutputFileName (
    24. (const char *)chemGlobals->printerDefaultFilename() );
    25. qDebug() << (const char *)chemGlobals->printerDefaultFilename();
    26. // printer.setOutputToFile ( FALSE );
    27. // Set full page mode, in order to have control of page size
    28. printer.setFullPage( TRUE );
    29.  
    30. // Run the printer setup dialog, and if the user clicks 'ok' then
    31. // do the actual printing
    32. #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
    33. Q_CHECK_PTR(&printer);
    34. //if ( printer.setup( this ) )
    35. QPrintDialog *printDialog = new QPrintDialog(&printer, this);
    36. Q_ASSERT( printDialog );
    37. if( printDialog->exec() == QDialog::Accepted ) // HERE IT IS CRASHING...
    38. #else
    39. QPrintDialog printerDialog( &printer );
    40. printerDialog.setPrinter( &printer, TRUE );
    41. if( printerDialog.exec() )
    42. #endif
    43. {
    44. // Set the hourglass cursor
    45. QApplication::setOverrideCursor( waitCursor );
    46.  
    47. ------------------
    48. ------------------ // Other stuff for printing...
    49. -------------------
    50.  
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 

    Please tell me why it is CRASHING only in WINDOWS .
    Its working in LINUX properly.


    Hlep me ...!!!
    thanks in advance..

  2. #2
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Printing problem in windows

    WHY NOOOOO ...REPLY..???
    IS there anybody to help me or to give a hint...????

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Printing problem in windows

    Could you run it in debugger and paste the backtrace?
    J-P Nurmi

  4. #4
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Printing problem in windows

    Ok, I got know there is a problem
    in this code
    Qt Code:
    1. printer.setOutputToFile ( FALSE );
    To copy to clipboard, switch view to plain text mode 
    Once commented, the control goes to this
    Qt Code:
    1. if ( printer.setup( this ) )
    To copy to clipboard, switch view to plain text mode 
    Finally to this function..
    Qt Code:
    1. bool QPrinter::setup(QWidget *parent)
    2. {
    3. Q_D(QPrinter);
    4. return qt_compat_QPrinter_printSetup(this, d, parent)
    5. #ifdef Q_WS_MAC
    6. && qt_compat_QPrinter_pageSetup(this, parent);
    7. #endif
    8. ;
    9. }
    To copy to clipboard, switch view to plain text mode 

    The application crashes. Any idea

    Ok one more thing, I get this warning QPrintDialog, Only native format supported. What to do???

    -->Edit-->
    Ok I have changed the code from
    Qt Code:
    1. if (printer->setup(parent))
    2. ...
    3. you can rewrite it as
    4. QPrintDialog dialog(printer, parent);
    5. if (dialog.exec())
    To copy to clipboard, switch view to plain text mode 
    Still there is crashing, I still get QPrintDialog, Only native format supported,
    In int QPrintDialog::exec() function "ep" which is "QWin32PrintEnginePrivate *ep;" is 0. Any idea???
    Last edited by joseph; 12th July 2007 at 07:16.

  5. #5
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Printing problem in windows

    Quote Originally Posted by joseph View Post
    Ok, I got know there is a problem
    in this code
    Qt Code:
    1. printer.setOutputToFile ( FALSE );
    To copy to clipboard, switch view to plain text mode 
    Once commented, the control goes to this
    Qt Code:
    1. if ( printer.setup( this ) )
    To copy to clipboard, switch view to plain text mode 
    Finally to this function..
    Qt Code:
    1. bool QPrinter::setup(QWidget *parent)
    2. {
    3. Q_D(QPrinter);
    4. return qt_compat_QPrinter_printSetup(this, d, parent)
    5. #ifdef Q_WS_MAC
    6. && qt_compat_QPrinter_pageSetup(this, parent);
    7. #endif
    8. ;
    9. }
    To copy to clipboard, switch view to plain text mode 

    The application crashes. Any idea

    Ok one more thing, I get this warning QPrintDialog, Only native format supported. What to do???

    -->Edit-->
    Ok I have changed the code from
    Qt Code:
    1. if (printer->setup(parent))
    2. ...
    3. you can rewrite it as
    4. QPrintDialog dialog(printer, parent);
    5. if (dialog.exec())
    To copy to clipboard, switch view to plain text mode 
    Still there is crashing, I still get QPrintDialog, Only native format supported,
    In int QPrintDialog::exec() function "ep" which is "QWin32PrintEnginePrivate *ep;" is 0. Any idea???
    Ok, got it... I need to do this
    printer.setOutputFormat ( QPrinter::NativeFormat );
    and works fine.
    Is it correct????

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Printing problem in windows

    Just curious, what's the file name?

    QPrinter::setOutputFileName():
    This can change the value of outputFormat(). If the file name has the suffix ".ps" then PostScript is automatically selected as output format. If the file name has the ".pdf" suffix PDF is generated. QPrinter will use Qt's cross-platform PostScript or PDF print engines respectively. If you can produce this format natively, for example Mac OS X can generate PDF's from its print engine, set the output format back to NativeFormat.
    J-P Nurmi

  7. #7
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Printing problem in windows

    Quote Originally Posted by jpn View Post
    Just curious, what's the file name?

    QPrinter::setOutputFileName():
    Aaha, That was the problem... the filename is "file.ps" so accroding to comments, fileFormat is taken as PDF.

    Thanks a lot.

Similar Threads

  1. Qt + Portmidi in Windows... libraries problem
    By hipogrito in forum Newbie
    Replies: 2
    Last Post: 19th June 2009, 01:01
  2. qt deployment problem on windows xp
    By sepp in forum Installation and Deployment
    Replies: 3
    Last Post: 5th July 2007, 12:16
  3. Thread problem with windows
    By vratojr in forum Qt Programming
    Replies: 17
    Last Post: 16th June 2006, 09:34
  4. Replies: 10
    Last Post: 28th April 2006, 16:48
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 09:08

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.