qlabel pixmap() crash

384 views
Skip to first unread message

Luigi Ferraris

unread,
Jun 29, 2016, 1:22:30 PM6/29/16
to QtContribs
Hi Pritpal,
I'm using QLabel to show image using :setPixmap(const QPixmap &) and works fine.
While testing my program, I forgot to set pixmap; AFAIK :pixmap() must return something ( probably a pointer using C++ ) but program goes in crash..
To be ensure I have used hb_trace( HB_TR_ALWAYS, VALTYPE( oLabel:pixmap() ) )
I'm using HbQt revision 425
Regards
Luigi

Luigi Ferraris

unread,
Jun 29, 2016, 1:49:54 PM6/29/16
to qtcon...@googlegroups.com
Il 29/06/2016 19.22, Luigi Ferraris ha scritto:
Hi Pritpal,
I'm using QLabel to show image using :setPixmap(const QPixmap &) and works fine.............
I'm reading QLabel.cpp (compiler output) and I see
HB_FUNC_STATIC( PIXMAP )
{
   QLabel * p = ( QLabel * ) hbqt_par_ptr( 0 );
   if( p )
   {
      hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap( *( p->pixmap() ) ), "HB_QPIXMAP", hbqt_del_QPixmap, HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
   }
}

I'm not sure (I'm not a C programmer) but probably it would be
HB_FUNC_STATIC( PIXMAP )
{
   QLabel * p = ( QLabel * ) hbqt_par_ptr( 0 );
   if( p )
   {
      hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap( p->pixmap() ), "HB_QPIXMAP", hbqt_del_QPixmap, HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
   }
}

Regards
Luigi

Pritpal Bedi

unread,
Jun 29, 2016, 3:51:18 PM6/29/16
to QtContribs, luigfe...@gmail.com
Hi Luigi



I'm reading QLabel.cpp (compiler output) and I see
HB_FUNC_STATIC( PIXMAP )
{
   QLabel * p = ( QLabel * ) hbqt_par_ptr( 0 );
   if( p )
   {
      hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap( *( p->pixmap() ) ), "HB_QPIXMAP", hbqt_del_QPixmap, HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
   }
}

I'm not sure (I'm not a C programmer) but probably it would be
HB_FUNC_STATIC( PIXMAP )
{
   QLabel * p = ( QLabel * ) hbqt_par_ptr( 0 );
   if( p )
   {
      hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap( p->pixmap() ), "HB_QPIXMAP", hbqt_del_QPixmap, HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
   }
}



Did you try to compile the above code ?


Pritpal Bedi
a student of software analysis & concepts 

Pritpal Bedi

unread,
Jun 29, 2016, 4:00:37 PM6/29/16
to QtContribs
I'm using QLabel to show image using :setPixmap(const QPixmap &) and works fine.
While testing my program, I forgot to set pixmap; AFAIK :pixmap() must return something ( probably a pointer using C++ ) but program goes in crash..


I have no idea why it would crash. 
It will through a RTE if the parameter is not of type pixmap.

Luigi Ferraris

unread,
Jun 30, 2016, 8:52:06 AM6/30/16
to QtContribs
Hi Pritpal,
first of all: remember I'm not a C programmer so take my answer with care :-))

I have compared (ie) QTablewidget.cpp related with method currentItem() and I read this C code
HB_FUNC_STATIC( CURRENTITEM )
{
   QTableWidget * p = ( QTableWidget * ) hbqt_par_ptr( 0 );
   if( p )
   {
      hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, p->currentItem(), "HB_QTABLEWIDGETITEM", hbqt_del_QTableWidgetItem, HBQT_BIT_NONE ) );
   }
}

As you can see p->currentItem is used (I think) to create and return a HB_QTABLEWIDGETITEM. For this reason I thought my code was the right; but I have read other code related with metod :itemPrototype() and here I see hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QTableWidgetItem( *( p->itemPrototype() )that is (more or less) the same code as original QLabel.cpp. So, I'm very confused.


Did you try to compile the above code ?
 How can I do? Because the QLabel.cpp source code is auto created through hbmk2_qt.hb (it is my guess)

I have no idea why it would crash. 
It will through a RTE if the parameter is not of type pixmap.
why do you propose this hypothesis? Where is the code that emits RTE? There isn't into QLabel.qth. Again can be related with
hbmk2_qt.hb?

I think the code must be (more or less)

HB_FUNC_STATIC( PIXMAP )
{
   QLabel * p = ( QLabel * ) hbqt_par_ptr( 0 );
   if( p )
   {
      if p->pixmap() == 0 {
         hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap() ), "HB_QPIXMAP", hbqt_del_QPixmap,     HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
      } else {
         hb_itemReturnRelease( hbqt_bindGetHbObject( NULL, new QPixmap(
p->pixmap() ) ), "HB_QPIXMAP", hbqt_del_QPixmap, HBQT_BIT_NONE | HBQT_BIT_OWNER ) );
      }
   }
}

In some way I'm checking pixmap; if it is 0 I create a new empty QPixmap else I need to return a QPixmap copy. Probably,
for a C programmer there is a best code.

Regards
Luigi

Luigi Ferraris

unread,
Jun 30, 2016, 9:05:33 AM6/30/16
to QtContribs
Hi Pritpal,


Il giorno giovedì 30 giugno 2016 14:52:06 UTC+2, Luigi Ferraris ha scritto:

I have no idea why it would crash. 
It will through a RTE if the parameter is not of type pixmap.
why do you propose this hypothesis? Where is the code that emits RTE? There isn't into QLabel.qth. Again can be related with
hbmk2_qt.hb?


Perhaps, You are thinking about QPixmap.cpp where there is argument check; it's true ?

I tested picture() method (without setting any picture) and I get a crash with hb_out.log; the same as...

Luigi

Pritpal Bedi

unread,
Jun 30, 2016, 11:23:00 AM6/30/16
to QtContribs
So now you know the answer yourself.


 
I tested picture() method (without setting any picture) and I get a crash with hb_out.log; the same as...


This gpf cannot be handled as it is raised by Qt's engine. 
Reply all
Reply to author
Forward
0 new messages