>Selecting

>I ran into something peculiar today when using the Model/View classes in Qt 4.2 – probably something related to TaskTracker issue 143383. To demonstrate, let’s start with a minimal model that can be reset from a public method:

class MyStringListModel : public QStringListModel
{
public:
MyStringListModel( const QStringList &items ) : QStringListModel( items, 0 ) {}

void resetModel() { reset(); }
};

I start by initializing the model and viewing it through a QListView:

  QListView listView;
QStringList items;
items << "Kalle" << "Olle" << "Albert" << "Sven" << "Anders" << "Markus";
MyStringListModel model( items );
listView.setModel( &model );

Then I set the current index and select it – this is equvalent to picking it with the mouse (that was how I ran into the issue):

  listView.selectionModel()->setCurrentIndex(
model.index( 3, 0, QModelIndex() ),
QItemSelectionModel::SelectCurrent );

This gives us the following state:

  listView.selectionModel()->hasSelection() == true
listView.selectionModel()->selectedIndexes().count() == 1
listView.selectionModel()->currentIndex().isValue == true

Now, I reset the model:

  model.resetModel();

The situation changes to:

  listView.selectionModel()->hasSelection() == true
listView.selectionModel()->selectedIndexes().count() == 0
listView.selectionModel()->currentIndex().isValue == false

The same thing happens when using select instead of setCurrentIndex. When using the following line…

  listView.selectionModel()->select(
model.index( 3, 0, QModelIndex() ),
QItemSelectionModel::SelectCurrent );

… you get the following:

  listView.selectionModel()->hasSelection() == true
listView.selectionModel()->selectedIndexes().count() == 1
listView.selectionModel()->currentIndex().isValue == false

And after resetting the model it looks like this:

  listView.selectionModel()->hasSelection() == true
listView.selectionModel()->selectedIndexes().count() == 0
listView.selectionModel()->currentIndex().isValue == false

The TaskTracker entry says that the bug is fixed, so this is likely to have been fixed in the Qt 4.3 snapshots. If you’re using an earlier release it looks as if the selectedIndexes().count() is a better way to determine if something is selected.

>I visited the BitSim headquarters yesterday and got a chance to see the spring in Stockholm. It was nice to notice that it is slightly warmer in Gothenburg – but still far too cold for my taste – around 8 dgC.

It it would have been raining it would have been dangerously close to the Swedish standard temperature. It is 12 dgC. Combined with rain this is the Swedish standard weather. It is called just that because it could be chistmas eve or midsummer. It is is 12 dgC and raining you cannot tell.

Now it may sound as if Sweden is permanently cold and rainy. That is quite far from the truth. I’ve seen beautiful winterdays in the north with temperatures close to -35 dgC. In the summer we can reach around 30 dgC some days – and that is a bit too hot for my taste. I prefer around 25-27 dgC if I can be picky :-)

Anyway, enough about the weather. Stockholm was nice as always and it is always fun to visit the headquarters. This time I got a chance to have a closer look at the Badger demo – it was really cool. Live video, alphablended graphics and nearly no CPU load – it impressed the geek in me :-)

>My Collection of Gems

>I recently blogged about the way that GCC sometimes can write poetry. This has resulted in a small collection of gems and solutions: GCC Compiler Errors (and their meaning). Enjoy! If you want me to add something, do tell me. Either through a comment, or just mail me. I’m e8johan and use GMail.

The page is a part of the new wiki-based digitalfanatics.org – and the style sheets will need some more love before all is done. It is readable – but sometimes mixes colours that where not intended to be mixed. We’re currently in the process of moving contents to the wiki, so there will be changes but the links posted here aught to stay valid.

>GCC gems

>Everybody using GCC on a daily basis must have run into one of its hidden gems. Error messages that could be poetry, in a foreign language, written backwards. The message tells you pretty much – nothing. When you have found the problem and fixed you still wonder what GCC really meant and why it could not tell you something in English…

One of my personal favourites was when I was using C and wrote:

typedef struct { ... } Foo;

void function()
{
struct Foo foo;

...
}

Did you spot the mistake? GCC did – and told me this:

storage size of 'foo' isn't known

After much work I found that Foo wasn’t a struct, but a typedefed struct. Just skipping the word struct in the declaration of foo solved it.

What are your favorites? Comment!

>Pick a job – any job

>The Swedish National Agency for Higher Education – a.k.a. Högskoleverket – recently released as listing over the educations to pick if you want a job. I just wanted to give you my 0.05 EUR.

There are two problems with this list:

#1 If you are not interested in teaching or engineering – you will probably never be a good teacher or engineer. Only use the list if you want to pick a flavor – for example what kind of engineer that you want to be or at what level you want to teach.

#2 You are not the only one watching these lists. During the IT-boom everybody wanted to be an IT engineer. That meant that the backlash when the industry collapsed was unnecessary hard. By not going with the flow and instead pick something that you are genuinely interested in you are more likely to be able keep your job when bad times come. And bad times come now and then – if nothing else, that is something to learn from history.