QString enhancement request

Post Reply
seasoned_geek
Posts: 246
Joined: Thu Jun 11 2020 12:18 pm

QString enhancement request

Post by seasoned_geek »

Can this get fixed?

Code: Select all

/home/roland/sf_projects/roland_hughes-scintilla/copperspice/ScintillaEditBase/PlatCS.cpp: In member function ‘virtual void* Scintilla::DynamicLibraryImpl::FindFunction(const char*)’:
/home/roland/sf_projects/roland_hughes-scintilla/copperspice/ScintillaEditBase/PlatCS.cpp:1365:46: error: call of overloaded ‘QString8(const char*&)’ is ambiguous
 1365 |             fp = lib->resolve( QString( name ) );


Function FindFunction( const char *name ) override



/home/roland/sf_projects/roland_hughes-scintilla/copperspice/ScintillaEditBase/ScintillaCS.cpp:815:25: error: call of overloaded ‘QString8(const char*&)’ is ambiguous
  815 |     QString text( label );
      |                         ^
When porting a lot of code that interfaced to C stuff and was originally written in Qt, having to go back and wrap everything like this

Code: Select all

 QString text( QByteArray( label ) );      
gets really annoying. Can't the class have a constructor that accepts const char *cStr and does the QByteArray under the hood?
barbara
Posts: 443
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: QString enhancement request

Post by barbara »

QString text( QByteArray( label ) );
It is "permissible" to do this but not recommended and is somewhat inefficient. Since "label" is a const char * there is no encoding specified in the data type. The proper way is to use one of the following two lines of code. If all the chars of label are in ASCII then these are equivalent. Otherwise you need to know what encoding the text is in and use the conversion.

Code: Select all

QString text( QString::fromLatin1( label ) );

QString text( QString::fromUtf8( label ) );
. . . having to go back and wrap everything
This is not about "wrapping" just to make the code compile. The call to fromLatin or fromUtf8 is required to specify the encoding of the text. The constructor which accepted a const char * was removed intentionally since it does not specify an encoding.

Yes, it does take a bit of work to correct legacy code however the code will be correct and translations will work better.

Barbara
Post Reply