[Interest] Qt API annoyances: where to log/discuss?

Elvis Stansvik elvstone at gmail.com
Wed Oct 31 20:42:13 CET 2018


Den ons 31 okt. 2018 kl 18:35 skrev Jason H <jhihn at gmx.com>:
>
>
>
> > Sent: Tuesday, October 30, 2018 at 3:23 PM
> > From: "Thiago Macieira" <thiago.macieira at intel.com>
> > To: interest at qt-project.org
> > Subject: Re: [Interest] Qt API annoyances: where to log/discuss?
> >
> > On Tuesday, 30 October 2018 08:39:22 PDT Jason H wrote:
> > > I was wondering if there is a place to log annoyances/discuss with the Qt5
> > > API for fix in Qt6?
> >
> > This list or the development mailing list are fine.
> >
> > >
> > > Two I am thinking of right now is:
> > > - QUrl::port() returns an int, but QTcpServer accepts a quint16, so no
> > > matter what I do, unless I add a cast, I get a warning.
> >
> > That's because QUrl::port() can return -1, indicating "no port was set in the
> > URL". QTcpServer needs a valid port number. So the warning is correct and
> > should be acted on.
>
> I thought QUrl::port() can take a default port if not set. Does it need to be able to return negative?
>
> > > - Similarly with
> > > QImage::pixel there are signed/unsigned issues between pixel and qRgb().
> >
> > Sounds like something to be fixed.
> >
> > > Also, as I go between several languages, I find myself wanting to use
> > > lambdas more in a functional programming style. ( I would like a lambda for
> > > QImage::pixel ([] (x,y,pixelValue) { } ) (This one is neat because you can
> > > use scanline() transparently) Also for the various containers.
> >
> > Highly inefficient, so unlikely to happen.
>
> In my own testing it was not that inefficient. In fact the lambda using scanLine() was faster than using pixel(), but yes slower than using scanLine with for loops.
>
> >
> > As for the containers, use <algorithm> and C++2a Ranges.
>
> I attempted this recently, but failed to figure out how to do the following:
> QVector<int> triple = apply(QVector<int> {1,2,3},[](item) { return item*3;});
> or
> QVector<int> originals {1,2,3};
> QVector<int> triples = originals.apply([](item) { return item*3;});
>
> My options are std::for_each, std::transform, but they all have an ugly, over-complicated syntax.
>
> Compare that to:
>  std::vector<int> originals { 1,2,3};
>  std::vector<int> triples;
>  std::transform(originals.begin(), originals.end(), std::back_inserter(triples), [](int item){ return item*3; });

Sorry to say it, but welcome to C++ :)

No, mostly kidding. I think what you suggest sort of makes sense. If
Qt are to keep its containers, with a goal of offering an alternative
more convenient/Java-esque API, then a helper member function like you
suggest seems to fit that goal. Whether Qt still has this as a goal in
another matter. Maybe not to the extent that they once had?

For the pattern above, I guess one could make a generic helper in a
header of the application. I know e.g. Qt Creator has a bunch of such
helpers in its headers.

Elvis

>
> Sure the std way works 100% of the time, but I don't want to read that code, much less write it. I think there's something about how "friendly" and "beautiful" Qt code looks.
>
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list