hbQT - Post queries in this thread only

Moderator: Rathinagiri

Post Reply
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
bedipritpal
Posts: 122
Joined: Thu Sep 02, 2010 10:47 pm

Re: hbQT - Post queries in this thread only

Post 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.
enjoy hbIDEing... Pritpal Bedi
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
bedipritpal
Posts: 122
Joined: Thu Sep 02, 2010 10:47 pm

Re: hbQT - Post queries in this thread only

Post 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.
enjoy hbIDEing... Pritpal Bedi
User avatar
bedipritpal
Posts: 122
Joined: Thu Sep 02, 2010 10:47 pm

Re: hbQT - Post queries in this thread only

Post 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.
enjoy hbIDEing... Pritpal Bedi
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4012
Joined: Wed Jul 30, 2008 6:43 pm

Re: hbQT - Post queries in this thread only

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5480
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hbQT - Post queries in this thread only

Post 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. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply