Page 7 of 15

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 3:39 pm
by Roberto Lopez
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.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 4:54 pm
by bedipritpal
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.
hbQT is implemented like that, why FAQ ?

Qxxxx():new()
OR
Qxxxx():new( SomeParameters )

depends on the context you are constructing one.
Qxxxx():from( qPointerORqHbObject )
does not create a new object but just encapsulates the given object or pointer inside hbQT object.

Probably I need to clarify this behavior with some examples, I will try shortly.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 6:17 pm
by Roberto Lopez
bedipritpal wrote: hbQT is implemented like that, why FAQ ?
We already created a FAQ.

We are trying to register the knowledge we acquiring about HBQT in a FAQ file, to simplify the work of new contributors.

Some things that could appear as obvious, are creating problems for some of us, because of our lack of knowledge about HBQT.

I guess that registering key information as we know more about HBQT is a good thing that can help other people.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 9:07 pm
by Roberto Lopez
Pritpal,

I'm trying to start a print preview dialog with a printer selected from a print dialog, so I've done the following:

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)" )
<...>
But it causes a GPF at the signaled line.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 11:04 pm
by bedipritpal
Hi

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

/*----------------------------------------------------------------------*/

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.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 11:31 pm
by bedipritpal
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:

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)" )
<...>
But it causes a GPF at the signaled line.
Please check how QPrintPreviewDialog():new( ) is constructed.

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 ) ) );
}
QPrintPreviewDialog():new( qPrinter, qWidget ) => if you supply two parameters
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.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 11:31 pm
by Roberto Lopez
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!

I'll try.

Re: hbQT - Post queries in this thread only

Posted: Fri Sep 10, 2010 11:33 pm
by Roberto Lopez
bedipritpal wrote: Please check how QPrintPreviewDialog():new( ) is constructed.

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 ) ) );
}
QPrintPreviewDialog():new( qPrinter, qWidget ) => if you supply two parameters
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.
Thanks for the info.

I'll try.

Re: hbQT - Post queries in this thread only

Posted: Sat Sep 11, 2010 1:26 am
by Roberto Lopez
bedipritpal wrote: So, you may send the object of application window as 2nd parameter and it will work.
It works perfect now.

Thanks again.

Re: hbQT - Post queries in this thread only

Posted: Sat Sep 11, 2010 3:06 am
by Rathinagiri
So if a pointer is requested it must be a pointer via PRG code.
On c++ level it can be ZERO.
This is good. :)