It has some time gone since I implemented the plasma widget to show the in-time departure information for local public traffic in Dresden, so I thought it is the right time to do something similar again. My current location is Oslo and it is really cold here (-14 this night), so you really don't want to wait 10 minutes at the bus station for the next bus. Fortunately the local transport services trafikanten.no provides a WAP service that allows you to retrieve the departure information of busses, trams and subways as WML pages. WML is a XML based markup language, so one would immediately start the favorite editor and hack together a bunch of code that uses QNetworkAccessManager to load the document from the internet and QDomDocument or QXmlStreamReader to parse the documents for the relevant information. However this approach needs a lot of glue code, and writing that wasts a lot of valuable time...
So today I want present a more efficient and smart way of doing that: QXmlQuery
This class is part of Qt since 4.4 and provides an implementation for XPath and XQuery (in 4.5 also XSLT), both are query languages to extract parts of XML documents with a rich set of filter rules. Extracting the time information from our WAP services needs only 5 - 10 lines of code + the code for representing everything on the screen:
I could now list the source code of this application here and explain how it works, however that would be duplicated work because that is already done here ;)
So the application is only based on Qt, as it's part of the example applications for Qt 4.5, but maybe there is some brave soul that converts it into a real plamsa widget? You can currently choose the station you want to departure information for and even filter for the bus/tram/subway number you are interested in. More features are not planned, to keep the example small and if you live outside Oslo, the departure times won't help you anyway :) but it is an excellent example that shows, how to use QXmlQuery for accessing web services easily.
Download the latest release here: www.qt.io/download.
Qt 5.15 was developed with a strong focus on quality and is a long-term-supported (LTS) release that will be supported for 3 years.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu