Category: qt

  • Getting a Q_INVOKABLE C++ function reevaluated by QML engine

    Unfortunately, with all the normal magic of QML property bindings, getting a property updated in a setup that involves return values from functions isn’t really doable, like this:

    I’m told there is a low priority feature request for a way of signalling that a function now returns a different value and all properties using it should be reevaluated.

    I have so far discovered two different workarounds for that that I will be presenting here.

    Using an extra property

    Appending an extra property to trigger the reevaluation of the function is one way of doing it.

    with the following on the C++ side:

    This is a bit more code to write and to remember to use, but it does get the job done.

    Intermediate layer
    Another way is to inject an intermediate layer, an extra object, that has the function. It can even be simplified by having a pointer to itself.

    with the following on the C++ side:

    It seems a bit simpler for the reader on the QML side, but also gets the job done.

    I am not sure which way is the best one, but the intermediate layer has a nicer feeling to it when more complicated types are involved.

  • QImage and QPixmap in a Qt Quick item

    For reasons I don’t know, apparantly a Qt Quick Item that can show a QImage or a QPixmap is kind of missing. The current Image QML item only works with data that can be represented by a URL.

    So I wrote one that kind of works. Comments most welcome.

    It is found on git.kde.org: http://quickgit.kde.org/?p=scratch/sune/imageitem.git

    Oh, and the KDE End of Year fundraiser is still running. https://www.kde.org/fundraisers/yearend2014/. Go support it if you haven’t already.

  • KDE makes Qt

    Recently I was trying some statistics on the qtbase-module (where QtCore, QtGui, QtWidgets and so on lives) and was wondering who made them.
    Not based on their current paid affilation, like Thiago’s graphs, but if each commit was made by a person coming from KDE.

    So, I got hold of Thiago’s scripts, a lovely mix of perl and zsh, and a QtBase git repository. First steps was to try to classify people as person coming from KDE or not. Of course, I’m a KDE person. Thiago is a KDE person. David Faure is a KDE person. Olivier Goffart is a KDE person. Lars Knoll is a KDE person.

    By the help of the KDE accounts file, and some of the long time KDE contributors, I got after a half day of work a good list of it. Then next steps was trying to put it into Thiago’s perlscripts

    All of it kind of succeeded:

    qtbase-KDE.graph

    So, KDE people makes up for 40-60% of the weekly commits to QtBase. This is again shows that KDE is important to Qt, just as the reverse is. So, let’s keep KDE healthy.

    KDE is running a end-of-year fundraiser over here https://www.kde.org/fundraisers/yearend2014/. Go ahead and donate, and help KDE stay healthy. For your own sake. And for Qt’s.

  • CMake skeleton for small Qt projects

    For small Qt-projects, I have for a long time been using qmake, mostly because qmake -project gives me a working build in most cases, but once the project grows a bit, I have switched to cmake because there is just things there I like better.

    So, I thought how to start with cmake instead, and ended up writing a small script. I guess I should share it:

    I’ve saved it locally as cmake-qtproject – and it works with at least cmake 2.8.11.

    I hope wordpress doesn’t make too much mess of it. Have fun.

  • Announcing Rawatar – Qt5 libravatar client library

    So. following up on my previous post about implementing a libravatar server, this will be an announcement of a quick Qt5 based client library for libravatar – so that everyone can put avatars everywhere!

    Get it while it is hot on
    git.kde.org

    There isn’t much screenshots to show off, given it is effectively just converting a string with an email into a URL for a image.

    And thanks to Martin Sandsmark for coming up with such a great name. Now I expect him to show off what it can be used for. Another thanks goes to Andreas Hartmetz for going thru the code & api.

  • Fake Akrobat browser plugin

    So. for some reason, the danish tax authorities (Skat) has started requiring Adobe Acrobat for being able to see pdf files to work around a bug with handling of temporary files on Windows8 and shared computers and such.

    Luckily there is a couple of easy workarounds. Like modifying the Javascript to check things at runtime using some browser specific addons. Or just do it like I did and write a actual browserplugin. I cheated and used QtBrowserPlugin. Then my actual code was a couple of lines. Want to check it out? Look here: http://quickgit.kde.org/?p=scratch%2Fsune%2Ffakeacrobat.git. It just does enough to ensure the test succeeds. Work in: iceweasel and arora. For some reason, it doesn’t work in konqueror/webkit nor in konqueror/khtml.

  • Vote verifications

    In KDE e.V. (which is to KDE what SPI is to Debian, Jenkins and others) there is some times a need to vote. For example about accepting new members. Mostly about accepting new members. With the new vote system (ballot.kde.org), voters need to do a bit more to check their votes afterwards. basically

    • Take username
    • Your own secret
    • The vote token

    and sha256 it in the right order with the right separator chars and so on.

    All sha256 sums are published together with where the vote was, so voters can verify that they are counted correctly.

    After failing to construct a couple of times on the command line, I decided to write a small GUI app to help me instead.

    There it is. Nice. Simple. Effective.

    Sources available. http://quickgit.kde.org/?p=scratch%2Fsune%2Fkrapyl.git&a=summary – have fun, and remember to verify your votes.

  • Those small nice tools we all write

    Many of us out there writes small tools to just solve a simple task that you need. Here, I will present a tool I needed last night.

    I have a small job doing a wordpress site for some people, and I needed a image with the site title in a font matching some specific criteria (like a double story lowercase A and a small serif on lowercase L, while in general being a Sans Serif type).

    So what I needed was a application that let me write a word or a phrase, and see it written with all available fonts on the system.

    So, it took a little more than a effective hour and 120 lines of code to come up with this:

    Click to see image

    And if anyone cares, I have pushed the sources to git.kde.org.

    I’m sure many of you also have various such small apps. Let’s see them. That’s also you Eike and your svgtoy app :)

    Another thing I learned from this app is that the ukij fonts targetted the Uyghyr language actually is very interesting also for western europeans.

  • Network status aware apps

    Am I online or not?

    There is a summary at the end for the quick readers.

    It is in many modern applications important to be able to more or less gracefully handle if the application user is online or not. For example, there is no need to try to fetch emails if the device (computer, phone, tablet, laptop, …) doesn’t have network (wifi, cable, umts, ip over avian carriers, ..).

    KDE has of course made nice functionality for this, and here I will try to describe how to make your app network status aware and what to be aware of in the process.

    Solid background

    All this is going on in Solid, using two parts of Solid and a bit of KDE’s infrastructure:

    • libsolid
    • networkstatus KDED module

    The networkstatus KDED module is trying it best to gather information from the computer to see if one is connected or not. It has the possibility to gather information from various sources, and handle changes and such.

    The as of writing available sources that the networkstatus module gathers information from is

    • Network Manager
    • wicd
    • asking the linux kernel thru the abstraction layers ntrack and libnl
    • …connman might be work in progress

    Collecting from different sources is important, because some people might have configurations like “Manage wireless thru wicd”, “manage umts dongle with Network Manager” and “manage wired network with /etc/network/interfaces” and all of it needs to be combined.

    Solid reports, if wicd thinks “online”, and network manager thinks “offline” that the user is Connected..

    Solid States

    There is a enum with 5 values in Solid to describe the current state of the network:

    Connected is the easy state. Here, Solid knows that you are having some kind of connection according to at least one of the sources. But it might just be a local network connection, and not actually a internet connection. So one here should handle connection failures gracefully.

    Unconnected is a similar easy state. Here, Solid knows that you don’t have any internet connection according to the sources it knows about. One should here not try to do any networking.

    Connecting and Disconnecting is that a state change is happening, so that you can prepare to react on it.

    Solid also has the state of Unknown, used for cases where Solid doesn’t have the required data to actually know it. A example could be a system without any of the data providers. You should here probably try to connect, and be able to handle failures gracefully. Also described as ‘Proceed with caution’.

    The bright reader might here notice that one both in the Unknown and Connected case actually should do the same.

    Querying for network status

    At any given time:

    Here, we first query Solid for current status, and then if the state is Connected OR Unknown, then we proceed.

    Getting notified

    Maybe you don’t want the roundtrip of asking (resulting in a dbus rountrip each time) when you need to know the state changes. Then you of course can get notified.

    I guess this should be pretty self explaining.

    Summary

    • Ask Solid::Networking::status() for network status
    • Connect to statusChanged(Solid::Networking::Status) from Solid::Networking::Notifier to be aware of changes
    • Treat the states Unknown and Connected the same way.

    Oh. And I’m out looking for a job.