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

Thiago Macieira thiago.macieira at intel.com
Thu Apr 12 15:13:42 CEST 2012


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?

> 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".

> 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.

> Note that QtDeclarative right now installs a message handler with the const
> char * signature. That means if the patch is accepted, we'd need to
> synchronize the qtbase with a qtdeclarative update.

You can keep a temporary compatibility code in QtCore for the time being, with 
both signatures, and apply the conversion. Once qtdeclarative moves over, you 
can remove the old one.

-- 
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120412/48792c10/attachment.sig>


More information about the Development mailing list