PDA

View Full Version : Printing problem in windows



joseph
10th July 2007, 06:19
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 ....




void ChemCanvas::printToPrinter( const RouteList *routeList )
{


// printer object
#if (QT_VERSION < 0x030000)
QPrinter printer;
#else
QPrinter printer( QPrinter::HighResolution );

#endif
// original wcOrigin, saved to be restored after printing.
QPoint originalWcOrigin = wcOrigin;

// With this set as true, objectNeedsRepainting won't
// draw while scaling to printer canvas
printing = TRUE;

// Set default printer characteristics to conform to the current
// canvas settings.
printer.setPageSize ( mappings.pageSize() );
printer.setOrientation( mappings.orientation() );
printer.setOutputFileName (
(const char *)chemGlobals->printerDefaultFilename() );
qDebug() << (const char *)chemGlobals->printerDefaultFilename();
// printer.setOutputToFile ( FALSE );
// Set full page mode, in order to have control of page size
printer.setFullPage( TRUE );

// Run the printer setup dialog, and if the user clicks 'ok' then
// do the actual printing
#if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
Q_CHECK_PTR(&printer);
//if ( printer.setup( this ) )
QPrintDialog *printDialog = new QPrintDialog(&printer, this);
Q_ASSERT( printDialog );
if( printDialog->exec() == QDialog::Accepted ) // HERE IT IS CRASHING...
#else
QPrintDialog printerDialog( &printer );
printerDialog.setPrinter( &printer, TRUE );
if( printerDialog.exec() )
#endif
{
// Set the hourglass cursor
QApplication::setOverrideCursor( waitCursor );

------------------
------------------ // Other stuff for printing...
-------------------

}
}


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


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

joseph
10th July 2007, 13:52
WHY NOOOOO ...REPLY..???
IS there anybody to help me or to give a hint...????

jpn
10th July 2007, 15:09
Could you run it in debugger and paste the backtrace?

joseph
12th July 2007, 05:28
Ok, I got know there is a problem
in this code

printer.setOutputToFile ( FALSE );
Once commented, the control goes to this

if ( printer.setup( this ) )
Finally to this function..

bool QPrinter::setup(QWidget *parent)
{
Q_D(QPrinter);
return qt_compat_QPrinter_printSetup(this, d, parent)
#ifdef Q_WS_MAC
&& qt_compat_QPrinter_pageSetup(this, parent);
#endif
;
}

The application crashes. Any idea :confused:

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

-->Edit-->
Ok I have changed the code from

if (printer->setup(parent))
...
you can rewrite it as
QPrintDialog dialog(printer, parent);
if (dialog.exec())
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???

joseph
12th July 2007, 06:29
Ok, I got know there is a problem
in this code

printer.setOutputToFile ( FALSE );
Once commented, the control goes to this

if ( printer.setup( this ) )
Finally to this function..

bool QPrinter::setup(QWidget *parent)
{
Q_D(QPrinter);
return qt_compat_QPrinter_printSetup(this, d, parent)
#ifdef Q_WS_MAC
&& qt_compat_QPrinter_pageSetup(this, parent);
#endif
;
}

The application crashes. Any idea :confused:

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

-->Edit-->
Ok I have changed the code from

if (printer->setup(parent))
...
you can rewrite it as
QPrintDialog dialog(printer, parent);
if (dialog.exec())
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????

jpn
12th July 2007, 07:12
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.

joseph
12th July 2007, 08:04
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.