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

kai.koehne at nokia.com kai.koehne at nokia.com
Fri Apr 13 12:16:54 CEST 2012


> -----Original Message-----
> From: Beck Wolfgang (Nokia-MP/Brisbane)
> Sent: Friday, April 13, 2012 1:23 AM
> To: Koehne Kai (Nokia-MP/Berlin); thiago.macieira at intel.com;
> development at qt-project.org
> Subject: RE: [Development] Proposed API change: Change signature of
> QMessageHandler to use QString
> 
> Before I would do such a change I would check if there are other projects in
> QT they install their own messaghandler.
> I think they all need to change their code as well.
> Maybe we should keep it as it is.

Well, I'd like not to add a '//Qt6: Fix' comment at this point in time already ;)

But I'm now trying to keep the old API working for a transition period by adding a 'QtMessageHandler' instead of just changing 'QMessageHandler': https://codereview.qt-project.org/#change,22151 . The only breakage this will cause is for apps that call 'qInstallMessageHandler(0)'.

Regards

Kai


> Cheers,
>  WB
> 
> -----Original Message-----
> From: development-bounces+wolfgang.beck=nokia.com at qt-project.org
> [mailto:development-bounces+wolfgang.beck=nokia.com at qt-project.org]
> On Behalf Of Koehne Kai (Nokia-MP/Berlin)
> Sent: Friday, April 13, 2012 12:41 AM
> To: thiago.macieira at intel.com; development at qt-project.org
> Subject: Re: [Development] Proposed API change: Change signature of
> QMessageHandler to use QString
> 
> 
> > -----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
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list