Kate is maemo chief engineer in Forum Nokia,
She has long Linux/Open Source developer background.
kate.alhola | 22 October, 2010 15:11
Qt Creator is perfect tool for Qt application development, it is first IDE that i have fallen love and even as old hacker I have been ready to trade my old emacs to it. These is one missing feature that so many has asked from me, scratchbox support. It may be one of most requested feature among advanced Maemo/MeeGo developers. Currently QtCreator from Nokia SDK does not support Scratchbox toolchain. Most of current experienced Maemo developers prefer scratchbox because it allows also development of complex applications that are using in Linux build tools and it allows running application under simulated ARM or x86 environment with full Maemo library and style support. From picture above you can see exatly same application run under simulator and under scratchbox.
Getting Qt Creator supporting scratchbox is not so difficult, it just needs some small tweaks.
First make your paths symmetric under scratchbox and host Linux environment. That means that if your application path is /a/b/c/d under host, it is found under same path under scratchbox. I do this normally doing symlink my directory scratchbox under scratchbox home directory under /home/kate/scratchbox, so path to my application should be /home/kate/scratchbox/myapp under both scratchbox and host Linux.
You can do it with following command on Linux host.
mkdir
/scratchbox/users/$USER/home/$USER/scratchbox
ln
-s /scratchbox/users/$USER/home/$USER/scratchbox scratchbox
If you are running your scratchbox under VMWare virtual machine, you may want to have your working directory under host filesystem so that files are available also from your host side. This should least work under Linux and Mac hosts that both share common unix filesystem schematics. As example in Mac, I have under my Mac home directory subdirectory scratchbox that is mounted under my virtual Linux host as /mnt/hgfs . Under my VMWare Linux, i have from my Linux home directory symbolic link scratchbox -> /mnt/hgfs/scratchbox .
To have write access you need to have also matching UID's in both sides. Under Mac OSX default user is 501 but under Ubuntu it is 1001. To get matching user ID, you should make your user under Ubuntu have this same UID 501. By default system is not allowing it but you can change FIRST_UID to 500 and LAST_SYSTEM_UID as 499 in /etc/adduser.conf
To get this same VMWare host directory visible under scratchbox, you also need one extra step. Scratchbox is chrooted environment and it sees only files inside of chroot jail and this mount should be bind-mount to be visible by command
mount -o bind /mnt/hgfs/scratchbox /scratchbox/users/kate/home/kate/scratchbox
To compile, you need to create under your Linux host two shell scripts /usr/bin/sbox-qmake and /usr/bin/sbox-make as follows
/usr/bin/sbox-make
#!/bin/sh
/usr/bin/scratchbox
-d $PWD make $@
/usr/bin/sbox-qmake
#!/bin/sh
/usr/bin/scratchbox
-d $PWD qmake $@
You also need make them executable by
chmod 755 /usr/bin/sbox-qmake /usr/bin/sbox-make
Easy way to do it is use following cut and paste friendly way
echo '#!/bin/sh' >/usr/bin/sbox-qmake;echo '/usr/bin/scratchbox -d $PWD
qmake $@' >>/usr/bin/sbox-qmake;chmod 755 /usr/bin/sbox-qmake
echo
'#!/bin/sh' >/usr/bin/sbox-make;echo '/usr/bin/scratchbox -d $PWD
make $@' >>/usr/bin/sbox-make;chmod 755 /usr/bin/sbox-make
Under Qt Creator, you should go under projects, select desktop target because maemo target does not allow you to chose custom Qt version. Select desktop targer, section General, give configuration name, as example Sbox-qt, Choose “Manage” from Qt Version line and open Qt version management dialog. There, press “+” button and enter as “Version Name” sbox-qt and as “qmake Location” the location of your sbox-qmake script location /usr/bin/sbox-qmake . If everything went right, you should see text “Found Qt version 4.7.0 using mkspec linux-g++ (Desktop)”
When you return to “Build settings” page, your “Build steps” qmake should be already correct sbox-qmake. Make is still just “make”, you should select “details” from Make and set “Override make” as /usr/bin/sbox-make .
That's all, if everything went correctly, you could go back to your project and select form menu “Build” and “Build project: your project name”. It should build it under scratchbox and parsing error messages should also work.
For running your application from scratchbox, you need /usr/bin/sbox-run script, there is little trick here. Qt Creator expands symbolic links, so /home/kate/scratchbox becomes /scratchbox/users/kate/home/kate, scratchbox run-standalone.sh script does not like that kind of path, so prefix need to be removed
/usr/bin/sbox-run ( for fremantle )
#!/bin/sh
/usr/bin/scratchbox
-d `echo $PWD| sed -e "s_/scratchbox/users/[A-Za-z0-9]*/_/_"`
run-standalone.sh $@
You also need append export DISPLAY=:2 to end of your scratchbox .bashrc, following cut and paste friendly way
echo export DISPLAY=:2 >>/scratchbox/users/$USER/home/$USER/.bashrc
When all this is done, start your Xephyr from Linux host by
Xephyr :1 -host-cursor -screen 800x480x16 -dpi 96 -ac &
and under scratchbox
af-sb-init.sh start
Under your Qt Creator prohject, go to "Run" settings, Add "Custom executable" and there sbox-run and name of your executable asargument.
Now you can run your Qt application under scratchbox just pressing green run symbol from your Qt Creator.
Because Mac OSX is Unix based, it is with certain limitations possible to compile under VMWare scratchbox with little tricks. These instructions are not complete and you may need your own expementing to get them work. You need to do same thing, make paths symmetric. Under Mac OSX users home is /Users/<username>, and you need maka same symlink under scratchbox.
You can run scratchbox commands under VMWare using ssh, so make following versions of sbox-qmake and sbox-make scripts, replace kate/kathy as your username and virtual machine IP with your one.
/usr/bin/sbox-qmake
#!/bin/sh
ssh
kathy@172.16.109.212 "scratchbox -d $PWD qmake $@"
/usr/bin/sbox-make
#!/bin/sh
ssh
kathy@172.16.109.212 "scratchbox -d $PWD make $@"
You also need to set up your mac ssh public key under VMWare Linux .ssh/authorized_keys .
VMWare has nasty feature to change your virtual machine address in fly and these scripts have address as hard coded, more advanced scripts could take this address automatically or then we need find option from VMWare not to change address.
Before setting new Qt target you should create on mac host empty directory /usr/include/qt4 and copy /usr/share/qt4/mkspecs from your scratchbox to mac host filesystem. May be advanced scripts could tweak paths returned by sbox-qmake -query to point under virtual machine but tahat's future project. I have also tried “headless” scratchbox support using Mac OSX Xephyr as display but leas in my tests Xephyr has crashed. It may need building from sources up to date Xephyr but that's also possible future project. Advantage in Headless version is that VMWare appliance is completely hidden behind QtCreator.
No hope