ia: Benvenite! In mi blog io scribe in interlingua, italiano e anglese.

it: Benvenuti! Nel mio blog scrivo in interlingua, italiano e inglese.

en: Welcome! In my blog I write in Interlingua, Italian and English.

Cammino quindi penso - introduzione

Visto che vi scrivo (e parlo) poco in italiano, ho pensato bene di sfruttare il tempo delle camminate (per andare all'asilo, fare la spesa, ecc.) per "conversare" con voi.
Beh, "conversazione" non è proprio la parola adatta, dato che si tratta di monologhi, e magari senza nemmeno una grande struttura: semplicemente dirò quel che mi passa per la testa, commenterò notizie ed eventi. Questo è il primo video, registrato oggi:



Non so con che frequenza pubblicherò questi video, ed è pure probabile che alcune volte pubblicherò solo la versione audio, se mi trovo fuori quando è ancora scuro (qui il sole si sveglia tardino). Chi vivrà vedrà.
Devo anche dirvi che non credo che pubblicherò tutti i video qui nel blog, ma solo alcuni; se non volete perdervene nessuno, allora iscrivetevi al canale in YouTube.

Per chi non voglia vedere il mio bel faccione, ma voglia comunque ascoltarmi, c'è anche la versione solo audio, disponibile qui in soundcloud.

QML trick: force re-evaluation of a property binding

Everyone who has used the QML programming language should love its property binding mechanism, which is made very easy to express via its declarative paradigm:


import QtQuick 2.0

Column {
  TextEdit {
    id: inputField
  }
  Text {
    id: secondLabel
    text: "You typed: " + inputField.text
  }
}

If you have worked on a project where QML was used along with C++ code, you might have bumped into a scenario where some bindings don't seem to work as you'd expect:


import QtQuick 2.0

Text {
  text: cppModel.get(row, "description")

  MyCppModel {
    id: cppModel
  }
}

Whenever the value of the row variable changes, the property binding is re-evaluated and the text is correctly updated; however, if row is not changed and it's only the cppModel contents to change, then you'll be out of luck: the text won't update accordingly.
This apparently unexplicable behaviour has in fact an obvious explanation: the QML engine re-evaluates the property bindings only when a variable appearing in the expression (or in a javascript function used in the expression) is modified. But since in this case the function get() is a C++ method, the QML engine is not aware of this method's internals and does not see any change requiring refreshing the binding.

The first thing we have to do in order to solve this problem is to find a signal which tells us when it's time to re-evaluate the bindings. If you are working with a model derived from QAbstractItemModel, then you probably want to bind to the dataChanged signal, or maybe modelReset (if you simply reset the whole model when updating it). In the general case, your C++ class should have a signal or a property which gets updated when needed. If not, add it! :-)

The trick I've been using in some occasions is then to artificially trigger a change in a property used in the binding, in order to force the refresh:

import QtQuick 2.0

Text {
  text: cppModel.get(row, "description")

  MyCppModel {
    id: cppModel
    onDataChanged: {
      var tmp = row
      row = -1
      row = tmp
    }
  }
}

I know, I know, this is horrible. It works, but it causes the expression to be re-evaluated twice, since we are changing the row property twice. Besides, chaning the row property might have some unwanted side effects in other objects, if this property is used in other property bindings. And what if the C++ method doesn't take any parameters at all? How can we trigger its re-evaluation then?

I recently came up with another solution, which is the reason of this blog post. And yes, it's still a hack, but an elegant one. It uses the rarely used comma operator, which in Javascript works in the same way as in C++: it evaluates all operands, and returns the value of the last one. So, this is what we can do:


import QtQuick 2.0

Text {
  text: cppModel.updateCounter, cppModel.get(row, "description")

  MyCppModel {
    id: cppModel
    property int updateCounter: 0
    onDataChanged: updateCounter++
  }
}

Note that we've added an extra property, updateCounter, which we'll change whenever we want the binding expression to be re-evaluated. In this case I've added the property to the QML component, but if you own the C++ object you could add it to your C++ object. And of course, if your C++ object already has a property which gets updated when you also want to update the binding, then you can use that instead: it can be of any type, it doesn't have to be an int.

I hope you'll find this tip useful. :-)

Why Russians (and me) are cheering for Trump

Let me start by saying that I'm far from being a Trump fan, and that I believe that in this election the American people were voting between self destruction (Trump) and World War III (Clinton).
They could have voted for a far better candidate, whom the whole world would have envied them, that is Jill Stein. But the media and the propaganda campaign from the two main candidates ensured that people were just too worried of averting the risk of either self destruction or WW3 to take any other option into consideration. Hopefully time and experience will teach us, that in a democracy we must choose the option that we like the most, and not be calculators. But I digress.

Clinton's campaign has often hinted that Putin was cheering for Trump's victory. While the connection is not obvious at all, and the markets seems to think otherwise (now, as results are out, the Pound, Dollar and Ruble are down, while Euro is gaining), there's indeed some support for Donald Trump in the Russian media and people. And while I'm not Russian, I do share this feeling and I'd like to try to explain you the reasons. Given that I do not represent Russians, and that I might be completely misreading their thought, I'm going to use the first person from now on; so if you don't like what you read, just blame me. :-)

First of all, Trump has made some positive statements in the topics of Russia, and world peace in general, by appearing to be willing to rethink NATO's role. He also made clear that Russia would not have taken Crimea from Ukraine, had he been president, a statement which I like to read in the sense that he would have not supported the Maidan coup in the first place. And generally, Trump appears not to be fond on military interventions all other the world.

Secondly, while Americans and the West in general regard at the U.S. as the most perfect democracy, I do have a much more disillusioned view of democracy. Impopular laws are all over the world, referendums are held and then ignored (like the Greek bailout referendum in 2015, most referendums in Italy, and possibly the Brexit one too), decisions are being taken in secret and/or without any public debate (EU association agreement with Ukraine, EU sanctions against Russia, EU agreement on refugees with Turkey, etc.). Given that I'm convinced that Trump will simply not be allowed to be the U.S. president, as Julian Assange recently said, or that he'll have to radically change his positions on NATO and the finacial establishment if he wants to keep the power, it will be interesting to see how this "perfect democracy" will twist its rules or its president in order to overturn the legitimate electoral result. The hope is that this will help opening people's eyes to how our democracies are really being controlled by the big powers.

Third, the fact that Trump is despised by most intellectuals and politicians in the West is a perfect opportunity for Western countries to rethink their relationship with the U.S., and switch from a complete subjection to a more critical stance. Which does not mean that we should be hostile to the U.S., please do not misunderstand me on that, but simply stop blindly obeying any order coming from there and start thinking of our own interests.

These are my hopes; but to be realist, the most likely thing is that Trump will simply mutate his positions and become a puppet of the big powers and continue preserving the status quo, while continue screaming against Mexicans and immigrants, and continue with the current imperialistic policies and with the exploitable-poor-creating-machine (i.e., "war", which creates floods of cheap labour while we steal their countries' resources) all around the world. And with the media calmly telling us that our vote counts.