It's time for another lazy Saturday afternoon blog entry. Lazy because that's how I like Saturdays. No emails that need answering, no tasks that need fixing, just doing what I feel like. Sometimes hacking, sometimes making music, sometimes chatting. And almost traditionally some good Italian food. But let's digress towards a neat feature in Qt 4.3 that Girish and I implemented on Thursday.
Have you ever used QMimeSourceFactory in Qt 3? Yes yes, that mysterious class that tries to solve so many problems with a name that is totally unrelated to any of them. For example it helps to locate images embedded in HTML markup in labels and tooltips. You could just write ...
QMimeSourceFactory::defaultFactory()->addFilePath(QDir::homePath() + "/images");
... and when the tooltip is shown it would locate example.png in $HOME/images. That is because Qt 3's richtext module used QMimeSourceFactory to locate resources like that.
Now in Qt 4 we moved all the functionality that QMimeSourceFactory provided into their respective locations. For example through QTextBrowser's searchPaths() property or QTextDocument's addResource() / loadResource() functions. Or through the introduction of the Qt Resource System. Unfortunately we kind of overlooked the use-case where one wants to reference images on the filesystem from tooltips or labels with relative paths only. Of course it is possible to still make that working, for example by implementing a pseudo file engine. But that's not as convenient as one simple method call like in Qt 3. After quite a bit of discussion (with Jasmin and Andreas) we think we've found a nice solution. Say 'hello' to QDir's search paths:
QDir::addSearchPath("icons", QDir::homePath() + "/images");
widget->setToolTip("...by pressing the button ...");
QStringList allThumbs = QDir("icons:thumbnails/").entryList();
I think this is mostly self-explaining :). Since it is implemented at the file engine level it works with anything that uses them, including QFile and QDir of course.
And as usual a note of warning: APIs in snapshots may change ;-). It's all subject to change, as much as the wheather here in Oslo. But while it is finally cooling down here (giving hope for snow after Christmas) Qt development is only heating up. I like it that way :)
I also observed that pictures help to grab people's attention for blogs. But since I can't really post a screenshot of the header file I decided to post a picture of the self-made pizza I've just had instead (with Pesto, Rucola, Buffalo Mozzarella, Avocado, Olives and Mushrooms):
Subscribe to our newsletter
Try Qt 5.12 LTS Now!
Download the latest release here: www.qt.io/download.
Qt 5.12 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