[Development] Proposed API change: Change signature of QMessageHandler to use QString

kai.koehne at nokia.com kai.koehne at nokia.com
Thu Apr 12 16:41:27 CEST 2012


> -----Original Message-----
> From: development-bounces+kai.koehne=nokia.com at qt-project.org
> [mailto:development-bounces+kai.koehne=nokia.com at qt-project.org] On
> Behalf Of ext Thiago Macieira
> Sent: Thursday, April 12, 2012 3:14 PM
> To: development at qt-project.org
> Subject: Re: [Development] Proposed API change: Change signature of
> QMessageHandler to use QString
> 
> On quinta-feira, 12 de abril de 2012 08.17.37, kai.koehne at nokia.com wrote:
> > Hi,
> >
> > I'd like to get
> > https://codereview.qt-project.org/#change,22151,patchset=5
> > into 5.0/api_changes branch. It's one more change to the logging
> > framework, specifically to the signature of QMessageHandler (new in
> > 5.0, old QtMsgHandler is unchanged):
> >
> > void (*QMessageHandler)(QtMsgType, const QMessageLogContext &,
> const
> > char *);
> >
> > becomes
> >
> > void (*QMessageHandler)(QtMsgType, const QMessageLogContext &,
> const
> > QString &);
> 
> Maybe QChar *begin, int len?
> 
> Or QChar *begin, guaranteed to be NUL-terminated?

What's the advantage of having a QChar * in contrast to a QString? 

> > The reason is to avoid unnecessary string conversions, especially on
> > Windows. E.g.
> >
> > qDebug() << "Hello World";
> >
> > will right now result in
> >
> > const char * -> QString conversion in QDebug::operator(const char *)
> > (QString::fromAscii(), shouldn't this be QString::fromLatin1() btw?)
> 
> fromAscii() was correct in the sense of "from whatever the user used in
> developing source code".

Just realized that nowadays fromAscii==fromLatin1. So it's really just a matter of taste.

> > QString -> const char * conversion in QDebug::~QDebug()
> > (QString::toLocal8Bit())
> > const char *-> QByteArray conversion in
> > qMessageFormatString() for the default message handler a QByteArray ->
> > QString conversion in qWinMessageHandler() (QString::fromLocal8Bit)
> >
> > So we're converting from latin1 to utf16 to local8bit to utf16 :) The
> > patch mitigates this somewhat by passing const QString & as argument
> > to the message handler, instead of const char *.
> 
> I support this.
> 
> The message handler is new API and this change is not changing compatibility
> with Qt 4.
>
> I assume you will do a final UTF16-to-local8bit if the user installed a legacy 8-
> bit message handler.

Yes, that's already part of the patch.

> [...]

> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>      Intel Sweden AB - Registration Number: 556189-6027
>      Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden



More information about the Development mailing list