«Consider yourself Perfectible makes you Perfect!»
Posts tagged qt
Binary Tree Rebuilder
Feb 5th
Imagine you have a Binary Tree, with those characteristics:
- Nodes do not respect any order relation – In other words: it’s not a Binary Search Tree of any kind
- Every node appears once and only once within the tree

A nice Binary Tree
Then, your little brother passes by your desk and, to upset you, deletes the tree from your computer memory/HD (yeah, I know, I’m pathetic at inventing hypothetical situations
).
Fortunately though, you previously did a Pre-Order and an In-Order visit of your tree, and stored the result in an 2 nice array.
Can you rebuild the original tree structure out of this 2 array?
How are you going to rebuild it?
Yes, you can! (Sorry, I couldn’t resist). And it’s quite easy as well. What you have to do, is the following:
- Take the first element of the PreOrder Array and use it as root of a new tree
- Find the position of this New Node in the InOrder Array, scanning it from
0ton-1(nis the number of Nodes) - IF next element in the PreOrder Array is on the left of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from
0to theposition of the New Node in the InOrder Array -1. - IF next element in the PreOrder Array is on the right of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from the
position of the New Node in the InOrder Array +1ton-1. - Return the New Node
By the way, this doesn’t work. To fix it we should be more generic, specifying things a little bit better. Things like:
- Every recursive calls takes into account a portion of the InOrder array; in the case of the first call it’s the entire array
- There is going to be as much recursive calls as the number of elements in the PreOrder array
Of course, is a tree what we are talking about here: recursion is a MUST. More >
Serverless chat to reduce office distance
Jan 31st
This idea comes out for an old university-time idea: to write a serverless chat application. Of course, I’m aware of the complications and the problems that using Broadcasting could create, so this problems would be took in consideration by design.
But why now? I was thinking of a way to reduce the “office distances”: making easy to connect with a person who works in your own office. I know, it sounds a bit “creepy” to depend on an application to do that. After all you could just stand up and go to the colleague’s desk. And that’s what I’d normally do: nothing impossible.
But I can see that this is not always the case for every personality, and, sometimes, I fall in the same “shyness” (since in UK, no one believes me when I say “I’m shy”, but I actually am: I just use jokes to relax and break-the-ice). So months passes by, you never learn the name of some colleagues and so on. After all how many times you work in projects where more than 10 people are involved?
Acceptance-less
A system like this could explicitly avoid concepts like “accept a contact in your contact-list”: the contact list would be the list of all the clients connected to the network, no one excluded. I know you could probably do this kind of stuff configuring accordingly some server chat, but you need:
- Infrastructure, set up by an IT department
- Maintenance, provided by an IT department
Both this things are normally very rare resources to have in a classical office environment. IT is always evil
. Am I not right?
Cross platform by design
I have in mind Qt as the framework to build something like that. It already covers the most of the desktop environments, and it can be set to integrate nicely. Not like Java.
Features? No, for now brainstorming
Yeah, I could start to write a long list of all the features I think such software should have, but this post was more to ask the micro-crowd that reads my blog “what do you think of such an idea?”. Any idea will be took in consideration.
Features
Ok, that’s what I have in mind for now:
- Acceptance-less contact-list (I believe that’s a core one)
- Chat layout built into a WebView: styling through plugins of CSS(3) files
- Drag and Drop file-transfer (no-passthrough-server: imagine the speed on a lan!)
- Encryption: communication can be encrypted, encrypting the socket traffic one has opened with another client
- Position: this could be like a “status” info, but allowing the person to pin him/herself on a Office map, so that can be easy to find
Please advice for more
And after this chat?
Just stand up and go there: it’s not like your colleague is going to harm you or something.
QDetroBro: Experimenting with Qt on S60
Aug 13th
The best way to learn a new language or a new framework is to find an idea and implement it. So I’m doing for Qt on S60. So I decided to implement a dummy browser that has some smart/attractive/peculiar/interesting/funny bits. QDetroBro
Because I’m lazy to package and attach code, and because is always good the evolution of a project from the ground-up, I decided to post it on my GitHub account. You can find it at: http://github.com/detronizator/QDetroBro/tree/master.
It passed through 3 major phases:
- v0.1-beta – Ultra-dummy browser with very “boring” UI. The entire code was in only 1/2 classes (power of Qt and Signal-Slots). Commit: f49bd…
- v0.2-beta – A lot of interesting new bits, like Animations, Stylesheet-themed Widgets and so on. Commit: dae20…
- v0.2.2-beta – The current release. Commit: 240c5…
If you want to take a look at it to see what Qt on S60 can enable, please do. You can download the latest build from here.
Ah, of course there are requirements to run Qt code on S60. You find what to install on your phone here (“Demos for your S60″ section).
Snippet: fix Screen Orientation in a Qt/S60 app
Aug 11th
I follow the Qt/S60 Mailing list, that is turning out to be a very interesting and active ML, and the Qt Labs blog, always full of very good code, written directly by the guys of Qt Software. I thought could be nice to start to post some of the stuff I’m learning.
#include <eikenv .h>
#include <eikappui .h>
#include <aknenv .h>
#include <aknappui .h>
// ...
// lock orientation
CAknAppUi* appUi = static_cast<caknappui *>( CEikonEnv::Static()->AppUi() );
if ( appUi ) //< Actually, this will always pass. It's a "static_cast" after all...
{
appUi->SetOrientationL( CAknAppUi::EAppUiOrientationPortrait );
}
// ...
Today’s source is: Nokia Forum.
