Wednesday, July 07, 2010
mSoma a Qt client for SomaFM
Andrea Grandi proposed me a few weeks ago to try and develop a client for SomaFM, a streaming radio with near 16 different channels, available for free. Indeed we wanted to try to develop an application for our cool Nokia N900 smartphone. Since this phone is now based on my beloved Qt framework, I accepted with much pleasure.
The really cool thing was that, by relying on the qt-mobility APIs (new Qt APIs for mobile application developers), we could enjoy cross-platform developing: all the code that I wrote for this player was tested and debuged on my computer, as a desktop application. Then, we deployed on the Nokia N900 and tried it there (and it worked seamlessly).
For instance, this are some screenshots of msoma running as a desktop application (in Linux in this case):
Of course, this is the very first version of this application, and surely the UI should be different in the desktop application with respect to the cellphone version (in order to be more usable in the mobile devices). But, as it is, it's already enjoyable (but I may be biased ;)
Source code is available on Gitorious and it's always updated with latest version we're working on. If someone want to test the application, it's available in extras-devel repository ("msoma" under Multimedia section) of N900.
In case you want to use it as a desktop application, please remember that you need qt-mobility. I blogged about the installation of qt-mobility in Linux.
We really want to thank, Rusty Hodge, SomaFM's founder, who provided so many details about SomaFM for developing our application (and of course we thank him also for SomaFM itself :)
We look forward to receiving feedback, patches, suggestions, and help! :)
Our maemo profiles:
Pubblicato da betto a 10:12 AM 1 commenti
Etichette: maemo, msoma, my programs, n900, nokia, qt, qt-mobility
Friday, June 18, 2010
Building Qt-Mobility in Ubuntu
Lately I started to try to develop applications for the Nokia N900, and the Maemo platform uses my beloved framework Qt :)
In particular, Nokia started to develop the Qt-Mobility Framework. Quoting from their white paper:
The Qt Mobility Project presents a collection of related software frameworks and interfaces. The objective being to deliver new Qt APIs for mobile application developers. Using these new APIs, developers will be able to create cross-platform applications targeting Maemo, Symbian and other platforms. This suite of features also has components that will be desirable to all users, not just those with mobile devices, so Mobility has advantages even for the desktop user.Thus, I wanted to try this project also on my Desktop (after all the intent of this framework is cross-platform development), and tried to compile qt-mobility on my Ubuntu/Kubuntu desktop. Unfortunately, I experienced many problems which now I seem to have solved, thus I'd like to share the steps to build qt-mobility from sources.
First of all, when installing qt-mobility after compilation, some files will be created in your current Qt installation. Thus, since I wouldn't want to spoil my qt installation from ubuntu packages, which is installed in system path, I downloaded the new qt framework 4.6.3 from the Nokia download site, and installed it in a path of my home: ~/usr/local/Trolltech/qtsdk-2010.03.
Then, I installed some packages that are useful to build qt-mobility and to enjoy media contents such as mp3 and videos, relying on gstreamer (not all these packages may be necessary, but after some tests, at least these packages will make things work):
sudo apt-get install libasound2-dev libbluetooth-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev network-manager-dev libxv-dev gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-ffmpeg w32codecs ubuntu-restricted-extras gstreamer0.10-plugins-good freeglut3-devThen, you need to get the sources of qt-mobility, and I got them from the git repository
git clone git://gitorious.org/qt-mobility/qt-mobility.git
However, you may want to get the stable sources (e.g., from qt-mobility download).
Since I'm a big fan of "shadow builds" which won't spoil your source directory, I built qt-mobility in another directory of my home, separate from the directory where I have the sources of qt-mobility (in this example the sources are in ~/install/qt-mobility): ~/build/qt-mobility/qt-4.6.3 (I specified the qt version I'm building qt-mobility with, since I may want to experiment with different qt versions):
- cd ~/build/qt-mobility/qt-4.6.3
- PATH=~/usr/local/Trolltech/qtsdk-2010.03/qt/bin:$PATH ~/install/qt-mobility/configure -examples -prefix ~/usr/local/Trolltech/qt-mobility> output.txt
Once the configuration step is successful, you can start building qt-mobility and then install it:
- make
- make install
- install -m 644 -p /home/bettini/build/qt-mobility/qt-4.6.3/features/mobility.prf /home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/mkspecs/features/
- install -m 644 -p /home/bettini/build/qt-mobility/qt-4.6.3/features/mobilityconfig.prf /home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/mkspecs/features/
Now, you can test your qt-installation by running an example (which was built and installed), for instance the player demo or the weather demo:
- ~/usr/local/Trolltech/qt-mobility/bin/player
- ~/usr/local/Trolltech/qt-mobility/bin/weatherinfo_with_location
Now, let's try to see whether we're able to use qt-mobility in our programs.
We'll try to compile a very simple qt program using a class from the qt-mobility framework (QVideoWidget), though we won't do anything with that (just to see whether we can build the application).
here's the files of our project
myvideowidget.pro
QT += core gui
TARGET = myvideowidget
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
CONFIG += mobility
MOBILITY = multimedia
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QVideoWidget;
class QMediaPlayer;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
QVideoWidget *videoWidget;
QMediaPlayer *player;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QTextEdit>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
videoWidget = new QVideoWidget(this);
setCentralWidget(videoWidget);
}
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
now, you should run the qmake of your qt installation you've used to build qt-mobility, thus
- ~/usr/local/Trolltech/qtsdk-2010.03/qt/bin/qmake myvideowidget.pro
- g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/mkspecs/linux-g++ -I../../myvideowidget -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/include/QtCore -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/include/QtNetwork -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/include/QtGui -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/include/QtOpenGL -I../../../../usr/local/Trolltech/qtsdk-2010.03/qt/include -I/home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/include/QtMultimediaKit -I../../../../usr/local/Trolltech/qt-mobility/include -I../../../../usr/local/Trolltech/qt-mobility/include/QtMultimediaKit -I/usr/X11R6/include -I. -I../../myvideowidget -I. -o mainwindow.o ../../myvideowidget/mainwindow.cpp
- g++ -Wl,-O1 -Wl,-rpath,/home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/lib -Wl,-rpath,/home/bettini/usr/local/Trolltech/qt-mobility/lib -o myvideowidget main.o mainwindow.o moc_mainwindow.o -L/home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/lib -L/usr/X11R6/lib -L/home/bettini/usr/local/Trolltech/qt-mobility/lib -lQtMultimediaKit -lQtOpenGL -L/home/bettini/usr/local/Trolltech/qtsdk-2010.03/qt/lib -L/usr/X11R6/lib -lQtGui -lQtNetwork -lQtCore -lGLU -lGL -lpthread
Pubblicato da betto a 11:05 AM 2 commenti
Etichette: kubuntu, maemo, qt, qt-mobility, ubuntu
Saturday, November 28, 2009
QtFindReplaceDialog - a Find/Replace Qt dialog
Since I have not found an implementation of a Find /Replace dialog to be used in Qt text editor based applications, I thought I'd try to create one myself:
QtFindReplaceDialog is an implementation of a Find/Replace Qt dialog to be used in qt text edit based applications. A simple Find (only) dialog is also provided. The dialogs can be used as a library, or simply by importing the sources into your own applications. QtFindReplaceDialog is free and open source LGPL software.
- The project page for QtFindReplaceDialog is: http://qtfindreplace.sourceforge.net
- The git repository for QtFindReplaceDialog can be found here: http://gitorious.org/qtfindreplacedialog/qtfindreplacedialog
Pubblicato da betto a 7:10 PM 1 commenti
Etichette: qt, qtfindreplacedialog
Thursday, November 05, 2009
Compiling Qt 4.6 from sources
If you feel like trying the new Qt 4.6, which is currently in beta, and if you're using Linux, for which it is available only in source code package, or if you need the current development version from the git repository (for instance, for building the git repository version of Qt-Creator, you'll have to compile qt from sources.
This is quite straightforward, but I'll blog it here, in case it might provide some help for those who never compiled it.
If you obtained the source package, then you'll need to unpack it somewhere in your home.
If you want the git version (of course you need the git program), you'll first obtain the sources from the git repository:
git clone git://gitorious.org/qt/qt.gitand then switch to the 4.6 branch
cd qtNow, instead of compiling qt in the same directory where the sources are, let's make a shadow build, so that the source directory will stay untouched; this will also allow us to do possible several builds of the library (e.g., we may want to do a static build of the library, a debug build, etc.). Thus we create a build directory where we'll run the compilation (note that at the moment the build directory must be at the same level, thus we must not create the build directory inside the source directory).
git checkout -b 4.6 origin/4.6
Thus, for instance, this are the directories I have for building qt
bettini@bettini-desktop-karmic:~/install/qt-git$ ll(where qt is where you have the qt sources; in case you got the source archive, this directory might be called something like qt-everywhere-opensource-src-4.6.0-beta1).
total 8
drwxr-xr-x 2 bettini bettini 4096 2009年11月04日 21:33 build
drwxr-xr-x 17 bettini bettini 4096 2009年11月04日 21:33 qt
Now, let's enter the build directory and run the configure script. If you don't pass any -prefix option to configure, the library will be built to be installed into the directory /usr/local/Trolltech/Qt-4.6.0/):
cd buildyou'll have to answer some questions, and then you'll be ready to compile:
../qt/configure
Which edition of Qt do you want to use ?Now you're ready to run make and wait for about a couple of hours (even more if you don't have a fast machine); of course you may want to tweak the configuration so that you don't build some parts of qt (e.g., the examples); you may want to take a look at configure options by running configure --help.
Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.
Preparing build tree...
This is the Qt/X11 Open Source Edition.
You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
Type 'L' to view the Lesser GNU General Public License version 2.1.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.
Do you accept the terms of the license?
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/Trolltech/Qt-4.6-git
To reconfigure, run 'make confclean' and 'configure'.
After compilation ended, you can install the library; if you chose to install it in a path which is not your home, remember that you need superuser privileges:
sudo make installWhen this ended, you'll have your qt installed in the path specified at configuration time (or the default one), e.g.:
bettini@bettini-prog-karmic:~$ ll /usr/local/Trolltech/Qt-4.6.0/Note that sometimes documentation is not installed (you can take a look at the doc directory which should have html and qch subdirectories). I experienced this if I use a different prefix at configuration time. If this is the case, you need to first build explicitly the documentation with make docs and then, run the same configure command again (i.e., with the same options), and then run the make install command another time, and the documentation should be installed correctly.
total 364
drwxr-xr-x 2 root root 4096 2009年11月05日 07:30 bin
drwxr-xr-x 22 root root 4096 2009年11月05日 07:29 demos
drwxr-xr-x 5 root root 4096 2009年11月05日 07:30 doc
drwxr-xr-x 36 root root 4096 2009年11月05日 07:29 examples
drwxr-xr-x 21 root root 4096 2009年11月05日 07:28 include
drwxr-xr-x 3 root root 4096 2009年11月05日 07:28 lib
drwxr-xr-x 96 root root 4096 2009年11月05日 07:30 mkspecs
drwxr-xr-x 2 root root 4096 2009年11月05日 07:28 phrasebooks
drwxr-xr-x 10 root root 4096 2009年11月05日 07:28 plugins
-rw-r--r-- 1 root root 332881 2009年10月13日 09:43 q3porting.xml
Now, you're ready to enjoy the qtdemo, by running /usr/local/Trolltech/Qt-4.6.0/bin/qtdemo
Now, if you have another version of qt already installed in your system (e.g., the one packaged for your distribution) and you want to use the one you've just compiled it?
Well, thanks to qmake, this is quite easy: it's just a matter of invoking the qmake of your compiled version of qt (instead of the one in the system path).
For instance, let's take the mdi example that comes with qt, and let's take, for instance, the one already installed in your system (if you don't have qt examples already installed from your distribution, you can still take the one that is in the sources you downloaded), and copy it into a local folder:
bettini@bettini-prog-karmic:~/tmp/qt$ cp -rf /usr/lib/qt4/examples/mainwindows/mdi .
cd mdi
If I want to build this example using the version of qt we've just compiled it's just a matter of running
/usr/local/Trolltech/Qt-4.6.0/bin/qmake mdi.proNow, if I run make, the g++ compiler will be invoked with the right include path and library path for our compiled version of qt:
makeFor instance, here's some output (note the -I and -L options):
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.6.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.6.0/include/QtCore -I/usr/local/Trolltech/Qt-4.6.0/include/QtGui -I/usr/local/Trolltech/Qt-4.6.0/include -I. -o main.o main.cppBy the way, note that the right version of the moc compiler is used (and the same holds for uic if your application needs it).
...
/usr/local/Trolltech/Qt-4.6.0/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.6.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.6.0/include/QtCore -I/usr/local/Trolltech/Qt-4.6.0/include/QtGui -I/usr/local/Trolltech/Qt-4.6.0/include -I. mdichild.h -o moc_mdichild.cpp
...
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/Qt-4.6.0/lib -o mdi main.o mainwindow.o mdichild.o moc_mainwindow.o moc_mdichild.o qrc_mdi.o -L/usr/local/Trolltech/Qt-4.6.0/lib -lQtGui -L/usr/local/Trolltech/Qt-4.6.0/lib -L/usr/X11R6/lib -lQtCore -lpthread
If you now run the mdi program, and choose the Help -> About Qt menu item, you'll get the proof you're using your version of qt 4.6
Let's do some more experiments, and recompile the mdi example with the system version of qt (thus, it's better to get rid of the mdi directory and get a fresh new copy of the mdi example). Now we use the system version of qmake:
qmake -versionand let's build the example this way
QMake version 2.01a
Using Qt version 4.5.2 in /usr/lib
qmake mdi.proNote that the compiler options are now different
make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o main.o main.cppIf we run the application and select the about qt menu item we can see that we have the 4.5 version of qt:
...
/usr/bin/moc-qt4 -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. mdichild.h -o moc_mdichild.cpp
...
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o qrc_mdi.o qrc_mdi.cpp
g++ -Wl,-O1 -o mdi main.o mainwindow.o mdichild.o moc_mainwindow.o moc_mdichild.o qrc_mdi.o -L/usr/lib -lQtGui -lQtCore -lpthread
However, you can run this application, which is built using qt 4.5, so that it uses the 4.6 version of the library you compiled from source (assuming that we are using dynamically linked library):
LD_LIBRARY_PATH=/usr/local/Trolltech/Qt-4.6.0/lib ./mdiThis will force the dynamic linker to use the 4.6 version of the dynamic libraries.
Again, you can get the evidence using the about qt menu item.
This is possible due to version 4.6 being backward compatible.
Have fun with Qt :-)
Pubblicato da betto a 9:03 AM 13 commenti
Thursday, July 16, 2009
Source-highlight-qt: A library for highlighting Qt documents using GNU Source-highlight
A few days ago I released a new software that uses the new library provided by GNU Source-highlight: Source-highlight-qt, "a library for performing syntax highlighting in Qt documents by relying on GNU Source-Highlight library".
This library provides an implementation of the qt abstract class QSyntaxHighlighter
class, and it deals both with Qt3 and Qt4 (you will need to build a separate version of the library for the two different qt frameworks). Please note, the Qt3 version has less features and it is there only for old qt applications; furthermore, QSyntaxHighlighter
class in Qt3 has some design problems which make it quite inefficient to use.
The library can be downloaded from the sourceforge site using this link: http://sourceforge.net/projects/srchiliteqt/files.
For standard usage, it's just a matter of executing this code (you can pass the language syntax, i.e., the source-highlight language definition file, to the init method):
QTextEdit *editor = new QTextEdit;We also suggest to take a look at the example program qeditexample, for some use cases of the library. Please notice that this qeditexample program is not intended to be used as an editor for production, it's just to show how to use source-highlight-qt library (and it uses the qt4 version).
srchiliteqt::Qt4SyntaxHighlighter *highlighter =
new srchiliteqt::Qt4SyntaxHighlighter(editor->document());
highlighter->init("java.lang");
This is a screenshot of the program qeditexample, editing a C file; basically most of the code is taken directly from the library. For instance, it provides the combo boxes for selecting the highlighting language and the output style (and they be connected to the editor, so that all the changes are automatically applied):
This is another screenshot, where we're editing a C++ file, with a different style
The library also provides a dialog to customize the output style:
Happy Qt Highlighting! :-)
Pubblicato da betto a 9:32 AM 0 commenti
Etichette: qt, source-highlight, source-highlight-qt
Wednesday, March 04, 2009
Qt Eclipse Integration
Recently, I started to play with Qt 4 also under Windows, in order to be able to port some of my Linux applications that use Qt. Usually, I'm using KDevelop under Linux to develop Qt applications, but under Windows? Then I noticed that Trolltech provides Qt Eclipse Integration, i.e., an Eclipse plugin to program Qt programs with Eclipse. So I gave it a try...
IMPRESSIVE, really a nice piece of software!
The installation is immediate, and you get a menu item to run Eclipse already setup to start programming with Qt (relying on the CDT plugin for the C++ part). To try it, I followed the tutorial you find here.
The new project wizard now provides also Qt project options:
Pubblicato da betto a 10:29 PM 11 commenti
Tuesday, February 17, 2009
Compiling Qt with MinGW in MSYS
Since I wanted to port some Qt4 applications (I always developed under Linux) in Windows, I downloaded from the trolltech site the Qt libraries for Windows (already compiled) which come with a minimal MinGW compiler to build windows applications. This was the first time I was using mingw, since I've always used cygwin instead.
The Qt installation comes with a start menu item called Qt Command Prompt, which sets all the environment variables for you in order to start building Qt applications.
I tried to build a Qt tutorial example with qmake in msys, and here comes the bad surprise: the Makefiles generated by qmake contains windows paths (e.g., for calling the moc compiler), which the Unix shell does not understand. Here's a screenshot with the error:
C:\Qt4円.4.3\bin/moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I'c:/Qt/4.4.3/include/QtCore' -I'c:/Qt/4.4.3/include/QtCore' -I'c:/Qt/4.4.3/include/QtGui' -I'c:/Qt/4.4.3/include/QtGui' -I'c:/Qt/4.4.3/include' -I'c:/Qt/4.4.3/include/ActiveQt' -I'debug' -I'.' -I'c:/Qt/4.4.3/mkspecs/default' -D__GNUC__ -DWIN32 cannonfield.h -o debug/moc_cannonfield.cppI then asked on the nice qtcentre forum, and they pointed me to this blog post where they says it's a well known problem, and that recently Qt can be used also from msys (since qmake will generate Unix shell paths). What wasn't clear to me was that you must recompile Qt libraries yourself to make it work also from msys.
make[1]: C:Qt4.4.3bin/moc.exe: Command not found
make[1]: *** [debug/moc_cannonfield.cpp] Error 127
That's what I've done, downloading the sources of Qt and compiling the libraries from msys.
IMPORTANT: I wasn't able to compile the Qt libraries with the standard MinGW distribution; I had to use the MinGW that comes with Qt installation (i.e., the file qt-win-opensource-4.4.3-mingw.exe).
I did this procedure:
- Set some environment variables (assuming that you unzip the sources in C:\qt-win-opensource-src-4.4.3:
export QTDIR=/c/qt-win-opensource-src-4.4.3/
export PATH=/c/qt-win-opensource-src-4.4.3/bin:$PATH
export QMAKESPEC=$QTDIR/mkspecs/win32-g++ - then you can run configure.exe (this will create the qmake binary and all the Makefiles)
- now run make and wait for about 3 hours!
Couldn't reserve space for cygwin's heap...
Now, if no other errors take place, you'll have your compiled Qt libraries, and binaries, that generate the right Makefiles.
By removing the previous Makefiles, running qmake again (this time it will generate Unix paths to executables), and then make, everything works fine, and you can build qt applications from the comfortable Unix shell: indeed, now, the moc invocation command line is:
C:/qt-win-opensource-src-4.4.3/bin/moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I'c:/qt-win-opensource-src-4.4.3/include/QtCore' -I'c:/qt-win-opensource-src-4.4.3/include/QtCore' -I'c:/qt-win-opensource-src-4.4.3/include/QtGui' -I'c:/qt-win-opensource-src-4.4.3/include/QtGui' -I'c:/qt-win-opensource-src-4.4.3/include' -I'c:/qt-win-opensource-src-4.4.3/include/ActiveQt' -I'debug' -I'.' -I'c:/qt-win-opensource-src-4.4.3/mkspecs/win32-g++' -D__GNUC__ -DWIN32 lcdrange.h -o debug/moc_lcdrange.cpp
Pubblicato da betto a 9:30 AM 5 commenti