Feeds:
Posts
Comments

The following project shows how to embbed Google Maps into a Qt application and how to control the map motion programatically.

The user interface is made of one QWebView containing a custom web page, and five QPushButton to move the map:

Image

The Google Maps widget is a web page displayed in a QWebView QWidget:

mView = new QWebView( this );
mView->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
QString fileName = qApp->applicationDirPath() + "/map.html";
QUrl url = QUrl::fromLocalFile( fileName );
mView->load( url );

The web page source code comes from a basic Google Maps API example, except that the link to the source of the javascript should be “http” instead of “https”:

<script type=”text/javascript” src=”http://maps.googleapis.com/maps/api/js?sensor=false”></script&gt;
<script type=”text/javascript”>
var map;

var myLatlng = new google.maps.LatLng(45.20297, 5.6995);

function initialize() {
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(45.20297, 5.6995),
mapTypeId: google.maps.MapTypeId.HYBRID,
zoomControl: true,
zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL },
};

map = new google.maps.Map(document.getElementById(‘map_canvas’), myOptions);
}

google.maps.event.addDomListener(window, ‘load’, initialize);

</script>

</head>
<body>
<div id=”map_canvas”></div>
</body>

Data is passed from the Qt application to the webpage using javascript. For example the following line will execute a javascript command to pan the map by 0 pixel in the x-axis direction and -10 pixels in the y-axis direction:

mView->page()->mainFrame()->evaluateJavaScript("map.panBy(0, -10);");

The source code of this project can be found here: https://docs.google.com/open?id=0B5yDBZt8fDFhNUpSeUZSaE1MU0E or there: http://github.com/adrienbailly/qmaps

[Sources]

Google Maps API Documentation: https://developers.google.com/maps/documentation/javascript/reference

QT QWebView Documentation: http://qt-project.org/doc/qt-4.8/qwebview.html

Microchip C18 compiler has the annoying habit of throwing warning #2058 (call of function without prototype) when you call a function taking no parameters even though the function prototype is declared. The solution is to add the ‘void’ keyword in place of the parameters in the function protoype:

char foo(); // this will cause a warning #2058 ...
char bar(void); // ... but this won't.

If you are working an a distant computer or a virtual machine this will help you:
$ cat /etc/issue
Ubuntu 10.04 LTS \n \l

For the kernel version:
$ uname -a
Linux tatooine 2.6.32-22-generic #33-Ubuntu SMP Wed Apr 28 13:28:05 UTC 2010 x86_64 GNU/Linux

To display the amount of free and used memory:
$ free -m
total used free shared buffers cached
Mem: 3896 3557 339 0 336 1023
-/+ buffers/cache: 2196 1700
Swap: 1155 0 1155

To gather some data about your hardware try lshw:
$ sudo lshw
tatooine
description: Computer
width: 64 bits
capabilities: vsyscall64 vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 0
size: 3896MiB
*-cpu
...

$ sudo apt-get install php5-cli

apt is probably still running in the background, wait until it finished. If it’s frozen kill the processes:
$ sudo pkill apt

Size of a directory

To know the size the current including all the subdirectories:
$ du -sh .

-s : only show the total size (ie: not the size of all files and subdirectory)
-h : display in Kb, Mb, Gb instead of byte only

Before:

<input type="submit" value="Go"></input>

After:

<input type="submit" value="Go" style="display:block;margin:0 auto;"></input>

http://www.quirksmode.org/css/display.html#block

When creating a virtual appliance with virtual box, the size of the virtual disk increases as you put more data into it. But even if you remove all this data the real size of the virtual disk will not decrease. This can be a major problem when it’s time to export the virtual appliance. Two steps are required to reduce the real size of the size of the virtual disk:

  1. Fill all remaining space on the virtual disk with a file containing zeros and then delete it:
    sudo dd if=/dev/zero of=/foobar; sudo rm /foobar

    dd is a Linux utility that copy an input file into an output file. In this case the input file is /dev/zero: this special character file produce a continuous flow of zeros. /foobar file is the destination file. Once the virtual disk is full, the copy will stop and the file /foobar will be deleted. This process can take lots of time: as a reference it took me 6 hours to fill a 100Gb virtual disk. Be aware that at the end this process the real size of the virtual disk will reach the virtual capacity of the virtual disk: exactly the opposite of what you want but this is necessary to ensure that all the space not occupied by files on the virtual disk is contains the null value.

  2. Next step is to remove all this unused space. Use the vboxmanage tool to do so:

Most of the above information comes from the article bellow and some personal tests:
http://www.michaelcole.com/node/13

Before you commit changes to a SVN repository, you might want to replace tabs by spaces in source code. Some text editor can be configured in order to do it automatically during the edition of the file:

  • Gedit: In the Edit / Preference / Editor menu check the “insert spaces instead of tabs” and set it to as many space characters as you want.
  • Eclipse: In the Window / Preference /  menu and under the “General / Editor / Text Editor” section set the “Displayed tab width” value to what suits your needs and check the “insert spaces for tabs” checkbox.

But sometimes you’re using another editor without this option or you copy paste code from a source that contains tabs characters. In this case you can use this script:

Here is a script that can help you:
#!/bin/bash
basename=${1##*/}
expand --tabs=2 $1 > /tmp/$basename
cp /tmp/$basename $1
rm /tmp/$basename

The “–tabs=2” option set the numbers of spaces to replace a tab.
Call the script with the filename in argument:
$ tab2space.sh myfilewithtabs.cxx

If you need this only once in your life you might want to consider using this free online tool instead: http://www.textfixer.com/tools/remove-white-spaces.php

Update Apr, 27th:
http://www.commandlinefu.com/commands/view/2312/find-and-replace-tabs-for-spaces-within-files-recursively
A one liner to replace all the tabs by spaces in all the files of a folder recursively:
$ find ./ -type f -exec sed -i 's/\t/ /g' {} \;
Adjust the number of spaces you want in the sed expression (replace X by space): ‘s/\t/XX/g’ for 2 spaces, ‘s/\t/XXXX/g’ for 4 spaces

Sometimes you just need to swap two variables, this is how you can do it without using a third temporary variable:
if($max<$min) list($max, $min) = array($min, $max);

It could be interesting to see the difference, performance-wise, with a more conventional approach like:
if($max<$min)
{
$temp = $max;
$max = $min;
$min = $max;
}

On the same subject:
http://tech.petegraham.co.uk/2007/03/29/php-swap-variables-one-liner/
http://www.jonasjohn.de/snippets/php/swap-two-variables.htm
http://www.bukisa.com/articles/30572_swap-variables-values-in-php
http://www.devmaster.net/forums/showthread.php?t=428