rathinagiri wrote:Yes. I too have got this simple thing only after some 10 hours of confusion!
Qxxxx():new() always gives the pointer to the QT object created.
Ohh no... I've spent a lot more than ten hours on that

We should add to the FAQ.
Moderator: Rathinagiri
rathinagiri wrote:Yes. I too have got this simple thing only after some 10 hours of confusion!
Qxxxx():new() always gives the pointer to the QT object created.
hbQT is implemented like that, why FAQ ?Roberto Lopez wrote:rathinagiri wrote:Yes. I too have got this simple thing only after some 10 hours of confusion!
Qxxxx():new() always gives the pointer to the QT object created.
Ohh no... I've spent a lot more than ten hours on that
We should add to the FAQ.
We already created a FAQ.bedipritpal wrote: hbQT is implemented like that, why FAQ ?
Code: Select all
QPrintDialog := QPrintDialog():New()
nResult := QPrintDialog:exec()
if nResult == 1 // accepted
qPrinter := QPrinter():from( QPrintDialog:printer() )
qPrnDlg := QPrintPreviewDialog():new( qPrinter , 0 ) //<-GPF
qPrnDlg:connect( "paintRequested(QPrinter)", {|p| paintRequested( p ) } )
qPrnDlg:exec()
qPrnDlg:disconnect( "paintRequested(QPrinter)" )
<...>
Code: Select all
METHOD HbqReportsManager:printPreview( qPrinter )
LOCAL qDlg, qInfo, qList, i, qStr
qPrinter := QPrinter():new()
qPrinter:setOutputFormat( QPrinter_PdfFormat )
qPrinter:setOrientation( ::qScene:orientation() )
qPrinter:setPaperSize( QRectF():from( ::qScene:paperRect() ):size() )
qDlg := QPrintPreviewDialog():new( qPrinter, ::qView )
qDlg:connect( "paintRequested(QPrinter)", {|p| ::paintRequested( p ) } )
qDlg:setWindowTitle( "HBReportGenerator : " + iif( !empty( ::cSaved ), ::cSaved, "Untitled" ) )
qDlg:move( 20, 20 )
qDlg:resize( 400, 600 )
qDlg:exec()
RETURN qStr
/*----------------------------------------------------------------------*/
METHOD HbqReportsManager:paintRequested( pPrinter )
LOCAL qPrinter := QPrinter():from( pPrinter )
::printReport( qPrinter )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD HbqReportsManager:printReport( qPrinter )
LOCAL qPainter, a_, qRectF, oHqrObject, qT
qPainter := QPainter():new()
qPainter:begin( qPrinter )
qPainter:setWindow( QRectF():from( ::qScene:paperRect() ) )
qPainter:setViewPort_1( 0, 0, qPrinter:width(), qPrinter:height() )
FOR EACH a_ IN ::aObjects
IF hb_hHasKey( ::hItems, a_[ 3 ] )
oHqrObject := ::hItems[ a_[ 3 ] ]
qRectF := QRectF():from( oHqrObject:geometry() )
qRectF := QRectF():new( TO_MMS( qRectF:x() ), TO_MMS( qRectF:y() ), TO_MMS( qRectF:width() ), TO_MMS( qRectF:height() ) )
qT := QTransform():from( oHqrObject:transform() )
qT:translate( 0,0 )
qPainter:resetMatrix()
qPainter:setWorldTransform( qT )
oHqrObject:draw( qPainter, qRectF, .f. )
ENDIF
NEXT
qPainter:end()
RETURN Self
/*----------------------------------------------------------------------*/
Please check how QPrintPreviewDialog():new( ) is constructed.Roberto Lopez wrote:Pritpal,
I'm trying to start a print preview dialog with a printer selected from a print dialog, so I've done the following:
But it causes a GPF at the signaled line.Code: Select all
QPrintDialog := QPrintDialog():New() nResult := QPrintDialog:exec() if nResult == 1 // accepted qPrinter := QPrinter():from( QPrintDialog:printer() ) qPrnDlg := QPrintPreviewDialog():new( qPrinter , 0 ) //<-GPF qPrnDlg:connect( "paintRequested(QPrinter)", {|p| paintRequested( p ) } ) qPrnDlg:exec() qPrnDlg:disconnect( "paintRequested(QPrinter)" ) <...>
Code: Select all
HB_FUNC( QT_QPRINTPREVIEWDIALOG )
{
if( hb_pcount() >= 2 && HB_ISPOINTER( 2 ) )
hb_retptr( new QPrintPreviewDialog( hbqt_par_QPrinter( 1 ), hbqt_par_QWidget( 2 ), ( Qt::WindowFlags ) hb_parni( 3 ) ) );
else
hb_retptr( new QPrintPreviewDialog( hbqt_par_QWidget( 1 ), ( Qt::WindowFlags ) hb_parni( 2 ) ) );
}
Thanks!bedipritpal wrote: This is how it should be used. Above code is a snippet of hbIDE. Adopt it to HMG context.
I am sure you will pickup relevant context from above.
Thanks for the info.bedipritpal wrote: Please check how QPrintPreviewDialog():new( ) is constructed.QPrintPreviewDialog():new( qPrinter, qWidget ) => if you supply two parametersCode: Select all
HB_FUNC( QT_QPRINTPREVIEWDIALOG ) { if( hb_pcount() >= 2 && HB_ISPOINTER( 2 ) ) hb_retptr( new QPrintPreviewDialog( hbqt_par_QPrinter( 1 ), hbqt_par_QWidget( 2 ), ( Qt::WindowFlags ) hb_parni( 3 ) ) ); else hb_retptr( new QPrintPreviewDialog( hbqt_par_QWidget( 1 ), ( Qt::WindowFlags ) hb_parni( 2 ) ) ); }
and in your case you are supplying 0 as 2nd parameter.
NOTE: constructor :new() is not exactly equal to the way Qt constructs on c++ level.
HbQT has to mimmic this behavior. So if a pointer is requested it must be a pointer via PRG code.
On c++ level it can be ZERO.
So, you may send the object of application window as 2nd parameter and it will work.
It works perfect now.bedipritpal wrote: So, you may send the object of application window as 2nd parameter and it will work.
This is good.So if a pointer is requested it must be a pointer via PRG code.
On c++ level it can be ZERO.