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
Commentstheoriginalgri | 22/10/2010, 21:33
Nice article :)
I did it the other way round: Copy the standard ubuntu cursors to the scratchbox environment (where all cursors are invisible ones by default) and then install QtCreator inside scratchbox. Log in to scratchbox and run "DISPLAY=:0 /path/to/qtcreator" and you're done. The only thing that has to be changed in QtCreator is the start commandline which should run "run-standalone.sh $yourapp" and also export the display to :2.
kate.alhola | 22/10/2010, 21:38
I added one screen shot and little explanation what need to be done for running application
kimitake | 24/10/2010, 12:29
I just tried on ubuntu8.10 using QtCreator2.0.1 (I have not installed Nokia Qt SDK)
My scratchbox has both 4.6.2 and 4.7.
I have set sbox-qt at Qt4 options of QtCreator but it shows as follow.
Qt version is not properly installed. please run make install
However according to the tooltip of sbox-qt at Qt4 options dialog, it seems to recognize /opt/qt4-maemo5/lib or include etc.
Any idea?
kate.alhola | 24/10/2010, 15:29
The scripts that i did are some amount of kludge to fake QtCreator .
Creator checks Qt version, by does Qt exists in directory returned by qmake -query QT_INSTALL_HEADERS and that would be
by default /usr/include/qt4 . Even application paths is made symmetric, library paths are not. Perfect solution would be mangel all paths returned
by qmake -query but workaround is just, install default system Qt packages with sudo apt-get install libqt4-dev in your ubuntu host and Creator
will be happy.
kimitake | 24/10/2010, 19:45
Thanks!
I just created symlink on ubuntu host as follow and QtCreator recognizes sbox-qt script properly.
ln -s /scratchbox/users/kimitake/targets/FREMANTLE_X86/opt/qt4-maemo5 /opt/qt4-maemo5
thp4 | 24/10/2010, 21:42
In the last code snippet of the section 'Compiler scripts' you wrote 'chmod' where you probably wanted to write 'echo'.
Other than that, great article :) Thanks!
eleonne | 19/11/2010, 21:30
Hi Kate!!! Great post. I'm in troubles here!!!! When I try to point to sbox-qmake in QtCreator, I get "This Qt Version has a unknown toolchain" error. So, reading the answers here I tryed the kimitake's solution. The problem is in my scratchbox, I got qt 4.7, but when I try to find the folder of QT in opt folder (/scratchbox/users/kimitake/targets/FREMANTLE_X86/opt/qt4-maemo5) there is nothing there. So, I don't know what to do. Please, help me!!!
eleonne | 19/11/2010, 21:34
Hi Kate!!! Great post. I'm in troubles here!!!! When I try to point to sbox-qmake in QtCreator, I get "This Qt Version has a unknown toolchain" error. So, reading the answers here I tryed the kimitake's solution. The problem is in my scratchbox, I got qt 4.7, but when I try to find the folder of QT in opt folder (/scratchbox/users/kimitake/targets/FREMANTLE_X86/opt/qt4-maemo5) there is nothing there. So, I don't know what to do. Please, help me!!!
XeN | 30/03/2011, 19:06
Hi,
thanks for the great tutorial I've looked a long for for a way of deveping with scratch and qt creator. but I have a problem at this step.
Instead of showing me "Found Qt version 4.7.0 using mkspec linux-g++ (Desktop)" there comes "This Qt Version has a unknown toolchain". So I seem to have the same problem as eleonne.
Is there a solution to this problem already?
ruipfcosta | 27/04/2011, 05:05
I've managed to compile and run a simple example for Maemo with Qt (TextEdit) on Scratchbox console and everything goes fine. However, I configured Qt Creator, but this example won't compile since "QAbstractKineticScroller" is unrecognized. I can run simple Qt apps so I believe this happens because this class is present only on Maemo Qt.
Is there a way to install any package on my Debian that allows me to compile these Maemo Qt examples that use specific classes for Maemo? If no, how can Qt Creator (or any IDE actually) be useful to program with this configuration (Xypher/Scratchbox)?
Step missed?
benlaud | 22/10/2010, 20:34
Hi ,
Thanks for the article. However, I have few questions about the process.
In the section of "Running under scratchbox" , I suppose it is a script to let Qt creator run the target on scratchbox in or not in VMWare. But what should I set on QT creator to accept the script? Just change the executable to /usr/bin/sbox-run?
Can I setup the QT creator to upload the compiled program to scratchbox which is running on VirtualBox?