read embedded resources

33 views
Skip to first unread message
Assigned to luigfe...@gmail.com by me

Luigi Ferraris

unread,
Jun 8, 2017, 9:16:00 AM6/8/17
to QtContribs
Hi Pritpal,
we can add embedded resource[s] using <thename>.qrc file and we know must be registered before use with "hbqtres_" + <thename> function.
With embedded resources we can add file (eg. text, translations, etc).
Following example on internet -related with .qss file- I start using this (adapted) code

LOCAL oFile
LOCAL cStyleSheet
LOCAL oString

oFile := QFile()
oFile:setFileName( <name_of_the_file> )

IF oFile:exists() .AND. oFile:open( QIODevice_ReadOnly )

   oString := QLatin1String( oFile:readAll() )
   cStyleSheet := oString:latin1()
   oFile:close()

   QApplication():setStyleSheet( cStyleSheet )

ENDIF


But it fails related with QLatin1String(...) because HbQt doesn't accept QByteArray as argument (see readAll() function )
As a workaround, I have used

   oB := oFile:readAll()
   cStyleSheet := oB:data()

  
AFAIK using oB:data() I can get hard data and they can be (give me a cent) encoded or not;
as example I read your demovisualizer.prg function __appLoadResourceAsBase64String

So the question: what is the best (or right) way to read/extract "data" from embedded resource file assumed
its content is text (IOW I'm thinking also to codepage problems)?

Regardless of the above problem, I noticed a difference between QLatin1String and HbQString, managing string argument; basically, both receive
string argument from somewhere

   QLatin1String
   ....... if( hb_pcount() == 1 && HB_ISCHAR( 1 ) )
   {
      pObj = new QLatin1String( hb_parcx( 1 ) );


   HbQString
   ...... if( hb_pcount() == 1 && HB_ISCHAR( 1 ) )
   {
      void * pText01 = NULL;
      pObj = new HBQString( hb_parstr_utf8( 1, &pText01, NULL ) );
      hb_strfree( pText01 );


Best regads
Luigi Ferraris

Luigi Ferraris

unread,
Jun 8, 2017, 4:45:59 PM6/8/17
to QtContribs
About reading file I found solution using QTextStream.
About QLatin1String I suggest to add

/*
 * QLatin1String ( const char * str )
 */
HB_FUNC( QT_QLATIN1STRING )
{
   if( hb_pcount() == 1 && hbqt_par_isDerivedFrom( 1, "QLATIN1STRING" ) )
   {
      __HB_RETPTRGC__( new QLatin1String( *hbqt_par_QLatin1String( 1 ) ) );
   }
   else if( hb_pcount() == 1 && hbqt_par_isDerivedFrom( 1, "QBYTEARRAY" ) )
   {
      __HB_RETPTRGC__( new QLatin1String( hbqt_par_QByteArray( 1 ) ) );
   }
   else if( hb_pcount() == 1 && HB_ISCHAR( 1 ) )
   {
      __HB_RETPTRGC__( new QLatin1String( hb_parcx( 1 ) ) );
   }
   else
   {
      hb_errRT_BASE( EG_ARG, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
   }     
}


Related with string as argument I don't know what hb_parcx returns but reading QTextStream.qth is coded the same as HbQString.

Regards
Luigi Ferraris

Reply all
Reply to author
Forward
0 new messages