Skip the packaging step in Qt Creator 2.0

I just figured that Qt Creator is now packaging every Maemo application whenever you tell it to run one. This might be annoying if packaging fails and will in any case slow down the whole process of debugging. However, if you want to skip the packaging step, this is not an option in Qt Creator 2.0(!).

Luckily the Qt developers over at Nokia are aware of this and have released a fix in the latest builds of Qt Creator. To acquire these, go to Qt’s snapshot homepage or just download the 32-bit or 64-bit versions for Linux directly from the build made on 12th of July.

Now you may select to skip the packaging by editing the build steps in Qt Creator.

Be aware that the snapshot versions are in development and may have bugs causing irrevocable data loss. That’s the risk you’ve got to take these days to avoid those bloated packages.

Posted in Mobile, N900, Programming, Qt | 2 Comments

Connect to your N900 while developing via usb

If you are developing for Nokia N900 using the Nokia Qt SDK, you are most likely following this guide to set up your environment. This is all nice and easy, but if you are connecting using usb you have to open a terminal each time you plug in your N900 and write

ifconfig usb0 192.168.2.14 up

If you, like me, get tired of doing this you may instead let Network Manager in Gnome do the work for you. First of all, connect your N900 via an available USB port. Next, right click the Network Manager icon and hit “Edit Connections…”.

This window will pop up. Press the “Add” button.

Type in a useful name, such as “N900 via usb”, and leave everything under “Wired” as is. Select the “IPv4 Settings” tab.

Set the Method to “Manual” and click “Add”.

Type in 192.168.2.14 as the address and 255.255.255.0 as the netmask. Leave the gateway blank.

Hit “Apply” and you are good to go!

Next, just click the Network Manager icon and select “N900 via usb”. If nothing went wrong, you should now be connected to your device, enabling you to use Qt Creator to its full extent. The next time you plug in your N900, Network Manager will do the work for you automatically.

Posted in Mobile, N900, Programming, Qt, Ubuntu | Tagged , , , , | 1 Comment

Loading wavefront .obj files in Qt’s OpenGL ES

I’ve been looking all over the web for a Qt library for loading files exported from Blender into OpenGL. Since I didn’t find anything I figured I would create a library myself.

Even though I didn’t find anything specifically about Blender and Qt’s OpenGL ES implementation, I managed to find something about each of them separately. Loading files from Blender seems to be most easily done by exporting to another format first. A lot of people mentioned Wavefront’s .obj file format as a good candidate. It is a small format, easy to parse and a lot of libraries already exist. At least that’s what they said.

Suzanne rendered with Qt and OpenGL ES

Finding a working .obj-loading library wasn’t that hard, but finding one that would load and compile nicely together with Qt was a bit harder. Finally I found GLM by Nate Robins, written way back in 1997. It might be old, but it certainly did the job. It even managed to draw on the screen! The next problem, however, was to make it draw with the newer OpenGL specifications. OpenGL ES 2.0 especially, since that’s what’s running on my Nokia N900.

The problem is that the old fixed API of OpenGL won’t compile with N900′s Scratchbox environment. I was close to giving up the whole GLM library, but I figured that I could try commenting out the functions which wouldn’t compile. And it worked!

I had to comment out glmDraw() and glmList(), and thus do the drawing on my own, but at least I had a library working which would load the files. I didn’t have to write all that myself, or even get into how .obj files are structured.

The next step was drawing the data. This was a bit of a pain, since the newer OpenGL ES API wants all data in certain arrays before drawing, while I was looking at just a bunch of vertices.

Stepping through the code in GLM, however, made me realize how it structured all groups and triangles from the .obj file, and made it possible for me to get these out and draw them on screen. Today I finally figured out how to draw the textures as well.

For testing I started with the hellogl_es2 example from Nokia and used this to draw my Blender monkey (named ‘Suzanne’). The whole example which now is loading the .obj model and drawing it on-screen is hosted over at GitHub. And for the interested, the main changed parts are loading the file and storing the data in arrays:

model = glmReadOBJ("monkey1.obj");
GLMgroup* group;
group = model->groups;
while (group) {
    Group grp;
    for(int i = 0; i < group->numtriangles; i++) {
        Triangle triangle;
        QVector verts;
        for(int j = 0; j < 3; j++) {
            QVector3D vector(model->vertices[3 * model->triangles[group->triangles[i]].vindices[j] + 0],
                             model->vertices[3 * model->triangles[group->triangles[i]].vindices[j] + 1],
                             model->vertices[3 * model->triangles[group->triangles[i]].vindices[j] + 2]);
            verts.append(vector);
        }
        QVector norms;
        for(int j = 0; j < 3; j++) {
            QVector3D vector(model->normals[3 * model->triangles[group->triangles[i]].nindices[j] + 0],
                             model->normals[3 * model->triangles[group->triangles[i]].nindices[j] + 1],
                             model->normals[3 * model->triangles[group->triangles[i]].nindices[j] + 2]);
            norms.append(vector);
        }
 
        QVector texs;
        for(int j = 0; j < 3; j++) {
            QVector3D vector(model->texcoords[2 * model->triangles[group->triangles[i]].tindices[j] + 0],
                             model->texcoords[2 * model->triangles[group->triangles[i]].tindices[j] + 1],
                             model->texcoords[2 * model->triangles[group->triangles[i]].tindices[j] + 2]);
            texs.append(vector);
        }
        triangle.vertices = verts;
        triangle.normals = norms;
        triangle.texcoords = texs;
        grp.triangles.append(triangle);
    }
    groups.append(grp);
    group = group->next;
}

And drawing the model:

glBindTexture(GL_TEXTURE_2D, m_uiTexture);
foreach(Group grp, groups) {
    foreach(Triangle triangle, grp.triangles) {
        program1.setUniformValue(textureUniform1, 0);    // use texture unit 0
        program1.enableAttributeArray(normalAttr1);
        program1.enableAttributeArray(vertexAttr1);
        program1.enableAttributeArray(texCoordAttr1);
        program1.setAttributeArray(vertexAttr1, triangle.vertices.constData());
        program1.setAttributeArray(normalAttr1, triangle.normals.constData());
        program1.setAttributeArray(texCoordAttr1, triangle.texcoords.constData());
        glDrawArrays(GL_TRIANGLES, 0, triangle.vertices.size());
        program1.disableAttributeArray(normalAttr1);
        program1.disableAttributeArray(vertexAttr1);
        program1.disableAttributeArray(texCoordAttr1);
    }
}

I will turn this all into a Qt OpenGL ES library in the future, but for now I figured you might be interested in a working example. Happy coding!

Posted in Uncategorized | Leave a comment

Moving around and going to github

I don’t think you’ll notice, but I’ve just moved this page permanently to dragly.org. There seems to have been some problems getting this site indexed properly when it was hosted on a subdomain of dragly.com. To get the site ut to speed I decided to move it. After all, what is a webpage without visitors? And how would you get here without the site being visible?

Alt text

I've found that github offers just what I need to host everything from small to big projects.

Until now we have been hosting dragly.com at One.com, but since they don’t support several domains I’m considering to move everything to ProISP.no where I’m currently hosting dragly.org. At the same time I think we’ll have to do something about those outdated webpages we’ve got there. We haven’t really updated those in a while.

On a completely different topic I’m trying out git at the moment as an alternative to Subversion. Way too many people have been talking positively about it lately, so I figured I needed to give git a shot.

First of all I’ve set up a profile over at github and am going to upload a few of my projects during the next couple of weeks. I’ve got too much source code lying around not to share it with everyone :)

And for starters that’s a big plus for github. Keeping my projects stored in one place makes it a much better alternative than hosting alternatives for Subversion, like SourceForge and Google Code.

Posted in Programming | Tagged , , | Leave a comment

How to draw a spring in Inkscape

I’ve been working on some free-body diagrams lately, and in my last paper I needed to draw a spring. Since I didn’t find any simple way to do this, I thought I should give a quick tutorial here.

First of all, turn on the grid by clicking SHIFT + 3 on your keyboard (the # key).

When your grid is turned on, enable the bezier curve editor by clicking this button:

Now, draw a shape similar to this. I’ve enabled the grid so you may see the distance between the points:

If you’re having trouble with the handles you may want to enable cornered points by clicking this button:

Next, you should make a copy of your newly drawn curve and open this for editing (double click on it).

Select the two leftmost points (as shown above) and delete these. Then move the new shape next to the other.

As you see, in my drawing the shapes don’t really fit. We’ll fix this by editing the second curve.

Now we’re soon done. All we need to do now is to exit editing mode by clicking the arrow tool:

Then select the second curve and copy + paste it as many times as you like:

Copy+paste the first shape and flip it

Now, move this to the end of the spring:

I did some final editing on the last part, but all in all you should be finished now! If you want to reuse this string, save it in a folder and import it when you need it or use it right away in your new diagram. Or just download the source here: Spring model.

Posted in Graphics, Inkscape, Tutorials | Leave a comment

Why I’m not using Ubuntu One

Recently I’ve had some issues with my previous solution for synchronizing files between my computers. I used to have an SSH server which I placed all my files on, and usually I edited them directly on this server. Whenever needed offline I used to synchronize them to my computers using Unison. Recently, however, the SSH connection to the server has been pretty sluggish on my laptop, causing the work flow to slow down.

I went looking for an alternative, and since Ubuntu comes with Ubuntu One preinstalled, I thought I should give it a try. The results were not even close to what I wanted.

First of all, there appears to be no kind of encryption on the Ubuntu One server – didn’t really bother me. I just set up an EncFS folder on my local computer and put all the files to synchronize inside this folder. The problem, however, occured when I needed to synchronize some of my papers while working on them. I went ahead and saved everything, waited a couple of minutes after seeing the message from Ubuntu One telling me that the files where syncing, and shut down the laptop. Back home, however, the sync would not start at first. I waited a little and when the sync seemed to have started, I opened the folder with the files – but, there where only my old files in there.

In frustration I picked up my laptop, put it on the desk, connected it to the Internet, and watched Ubuntu One sync the files over again. Wasn’t it supposed to do this four hours ago?

I went back to the main computer and looked at the folder, refreshed it, stared at it, cursed at it. Nothing happened. Not even after 30 minutes.

Okay. Back to looking for alternatives.

Spideroak and Dropbox

So, are all synchronization solutions this bad? You don’t have to worry, they are not even close!

I tried out Dropbox. Installed it and placed a few files in the Dropbox folder. Time to sync? I don’t have a clue. I didn’t even get to push the button on my stopwatch to check! Once the file was placed in the folder on my main computer, it was already on my laptop. Quite nice.

Spideroak on the other hand took 20 seconds or so before synchronizing, but that’s still an enormous improvement compared to Ubuntu One. And Spideroak has a couple of other benefits.

Where Dropbox only let’s you sync files in a specific folder, Spideroak let’s you set up several folders in different paths on your computer to sync. And you may also backup files which are not supposed to be synced.

The probably most important feature that Spideroak has is that the files are encrypted on each computer, making them unreadable even to the Spideroak employees. This is an important security measure which Dropbox lacks. On the other hand you could just put everything in an encrypted folder in the first place, which I think you should do even with Spideroak. The latter is because Spideroak decrypts the files when you watch them through the web-viewer, which means it’s technically possible to read your files when you are doing the same online.

Speed vs. features

I guess it’s up to you to decide what’s most important for you. The ease of use and speed which Dropbox offers, or the more advanced features and all over decent speed of Spideroak.

At the moment I’m running a sync of 900 MB of files using both solutions. I’ll update this post whenever they finish to give you some information about whether the speed differs on large synchronizations. Currently Dropbox is already syncing all the files, while Spideroak is “Pending new calculations”.

Posted in Ubuntu | Leave a comment

Python deleted my vector values

Sometimes scripting languages can be a real annoyance. Why? Because when you get as much help as you do with for instance Python, you also lose a lot of control.

Being used to scripting languages like PHP, I made the funny mistake today of initializing a set of arrays like:

a = v = r = zeros((n,2),float)

This seemed like a really good idea, saving me from typing two extra lines(!). As the sucker I am for short code I was happy with my newfound shortcut. What I didn’t realize is that Python, in comparison to PHP, treats assignments like these as pointers instead of variables.

I believed this would create three arrays with a lot of zeros in two dimensions as I would expect from PHP, but the result was that I instead created one array with loads of zeros in two dimensions, with three pointers a, v and r all pointing to the same array.

When I then started setting the values for each of these arrays using Euler’s method, the result was that I got a lot of nonsense in what I thought was three separate arrays.

As a reminder to myself and everyone else out there; Python is not PHP. If you want to initialize three arrays like this in Python, you’ll have to stick to  the long version:

a = zeros((n,2),float)
r = zeros((n,2),float)
v = zeros((n,2),float)

Or, you could at least save yourself from having to edit each assignment if you ever need to change the code by writing:

a = zeros((n,2),float)
r = a.copy()
v = a.copy()
Posted in Programming, Python | 2 Comments

Getting started with encrypted e-mail using Thunderbird and Enigmail

E-mail encryption is getting more and more important as more information is accessible to your ISP, e-mail provider or even your government. In this tutorial I won’t be going into any of the principles for why you should encrypt your e-mail or how it works – I rather assume that you have already realized the dangers of letting your personal e-mails swarm around on mail servers open for everyone to read.

Preliminaries

In this tutorial I’m going to use Thunderbird on Ubuntu. If you are running Windows or another Linux distro, you might need to do some extra modifications. I’ll see if I might implement those at a later point in time, but for the moment being you are on your own.

Installing Thunderbird

First of all, you should have Thunderbird installed. This is done through the Ubuntu Software Center, which you find by clicking Applications > Ubuntu Software Center.

Search for Thunderbird and install it by clicking the yellow arrow.

Then click “Install”.

When Thunderbird is installed, start it up by clicking

Applications > Internet > Thunderbird

When you start Thunderbird for the first time you’ll be asked to set up your account. The wizard which is used in Thunderbird is quite intuitive, so I won’t give you a explanation of it in this tutorial.

Installing the Enigmail extension

Now, we are going to install the Enigmail extension. This may be done through the Ubuntu Software Center as well, but since you might be running Windows or Thunderbird 3.0 (as I am), I’ll show you how you may do this through the interface in Thunderbird.

In Thunderbird, click

Tools > Add-ons

Search for Enigmail, and click “Add to Thunderbird…”

When prompted, restart Thunderbird.

Setting up Enigmail

There will be a new button next to “Tools” which reads “OpenPGP”. Click on

OpenPGP > Setup Wizard

Then click Next

Then Next again

Now, you should decide whether to sign and encrypt all your mail by default – that’s up to you, but I of course chose both.

This is for decryption (which only will be enabled for people you have a public key for).

Next, you may select whether you want Enigmail to disable/enable some things for you, to make sure it runs flawlessly. For instance, it disables HTML in outgoing messages, which some of you might not want. In that case, click Details… and change the values to whatever you want. Nothing will crash if you deselect these boxes, but some messages might not get decrypted as they are supposed to. If you don’t need fancy formatting in your messages, I suggest you leave everything checked.

The next part is to create a new public and private key:

Select an account and type in a passphrase:

And we are as good as done!

Click next, and Enigmail will do the rest for you.

Now, sit back and relax. Enigmail is creating your superduper encryption key while you are encouraged to surf the web.

When prompted, say yes to create a revocation sertificate (if you want to). Enigmail pretty much explains this itself.

And some more info…

That’s it for now. You should now be able to send and recieve encrypted messages using your key-pair!

More info will come about how to use your new safe e-mail!

Posted in Security | Leave a comment

Fixing a bug with python-visual in Ubuntu Karmic

I was preparing to do some tasks in my physics course today, and experienced a rather annoying problem when attempting to use the python-visual package in Ubuntu.

There seems to be a bug in Ubuntu Karmic which results in the following output when trying to run this command:

from visual import *

The output is as follows:

Traceback (most recent call last):
  File "cooper.py", line 1, in
    from visual import *
  File "/usr/lib/python2.6/dist-packages/visual/__init__.py", line 59, in
    import cvisual
AttributeError: 'Boost.Python.StaticProperty' object attribute '__doc__' is read-only

The fix is luckily quite simple.

Andrew Mitchell has a package repository for Ubuntu which contains an update to a library called “boost”. You can add this repository by selecting System > Administration > Software Sources. Then select “Other Software” and click on “Add…”.

Now, type in the following in the textbox:

ppa:ajmitch/ppa

Then click “Add source” and “Close”. If prompted, select “Reload” and then go to System > Administration > Update Manager. Click “Check” and then install all updates.

When this has been done, you are ready to run your python script.

Happy coding!

Posted in Programming, Python, Ubuntu | Leave a comment

Fixing “undefined reference to `vtable for …”

These annoying errors have been haunting me the last couple of days, so I figured I should share the most common reason for their occurrence. That is in my projects at least.

This error is caused because the linker in gcc is unable to find the functions you have defined in your headers in your actual code. So if you have a header which looks like this:

#ifndef MESH_H
#define MESH_H
 
class Mesh
{
public:
    Mesh();
    ~Mesh();
    virtual void draw();
};
 
#endif // MESH_H

You must at least have these functions defined in your .cpp file:

#include "mesh.h"
 
Mesh::Mesh() {
}
 
Mesh::~Mesh() {
}
 
void Mesh::draw() {
}

After this, make sure you clean your compile environment to make sure no object files are being misinterpreted by the compiler. If you are using Qt or a project with a Makefile, you could just run these three commands (the first only applies to Qt projects).

qmake
make clean
make
Posted in C++, Programming, Qt | Tagged , , , | Leave a comment