LXDE Blog

Divulgar conteúdo
blog.lxde.org
Atualizado: 13 minutos 43 segundos atrás

A Guide for Migrating from Gtk+ to Qt

qui, 25/04/2013 - 08:06
Since I started learning Qt recently, I noted some issues when trying to port Gtk+ programs to Qt. There are tons of tutorials for Gtk+ and Qt, but a guide for porting is lacking. Most of the articles comparing Gtk+ and Qt did not go into detailed issues people will encounter during coding. To help people porting their Gtk+ programs to Qt, I just started a wiki page documenting what I’ve learned so far. http://wiki.lxde.org/en/Migrate_from_GTK%2B_to_Qt Currently it provides a long table listing equivalent Qt classes for commonly used GtkWidget classes. Since I cannot find a similar list with Google, I built one. This is useless for experts, but it’s very handy and helpful for Qt beginners who already know Gtk+. The mapping between Gtk+ and Qt classes is not yet finished, but I’ll try to make it complete soon. I also documented things you need to know to safely mix glib/gio/GObject code with Qt. Later I’ll add docs describing how the translation systems differ. I hope that developers interested in this topic can help edit the wiki page to make it more complete and free from errors. It’s still a work in progress but I hope it helps someone as more and more people are using Qt and some more LXDE components *might* get Qt ports later. BTW, since Ubuntu guys is moving toward Qt, this also helps them. Cheers!

PCManFM Qt 0.1.0 released

ter, 26/03/2013 - 00:07
Hello world, I just released PCManFM Qt file manager 0.1.0, the first Qt port of PCManFM. The tarball is available for download from our project page. You’ll need libfm to build it (which is included in many distros). P.S. When running the program for the first time, please choose an icon theme from the [Edit] / [Preferences] menu. Otherwise you’ll get no file icons. If you install the program into /usr/local, don’t forget to run “ldconfig” after installation, or libfm-qt won’t be correctly loaded by the loader. This release contains no thumbnail support yet. However a fully working thumbnail support is already in the git. Because this requires some changes to the upstream libfm library, it’s scheduled for the next release and not make public at the moment. To turn on the desktop icon management feature, run with the command: > pcmanfm-qt –desktop
> Generally it’s a good idea to add this command to your session startup script. To turn the desktop icon manager off again, do this: > pcmanfm-qt –desktop-off > If you don’t want to use the desktop icons, you can still add the command to your session startup script: > pcmanfm-qt –daemon > In this way, it will becomes a background daemon. Every time you need to open a folder with pcmanfm-qt, it can be shown “immediately”. BTW, please don’t mail me and ask if PCManFM will shift to Qt. The Gtk+ and Qt versions will coexist. There will still be new releases for the Gtk+ version in the future. The Qt port is only an alternative, not a replacement. Thank you! — I, however, need to admit that working with Qt/C++ is much more pleasant and productive than messing with C/GObject/GTK+. Since GTK+ 3 breaks backward compatibility a lot and it becomes more memory hungry and slower, I don’t see much advantage of GTK+ now. GTK+ 2 is lighter, but it’s no longer true for GTK+ 3. Ironically, fixing all of the broken compatibility is even harder than porting to Qt in some cases (PCManFM IMO is one of them). So If someone is starting a whole new project and is thinking about what GUI toolkit to use, personally I might recommend Qt if you’re not targeting Gnome 3. Update 2013-03-27: I got some feedback about the toolkit choice above. Don’t get me wrong. I’m not saying that gtk+ is bad and did not intend to start a toolkit flame war. If you’re going to use python, C#, or other scripting language, gtk+ is still a good choice due to its mature language bindings.
Vala  is attractive initially, but after trying it in real development, you’ll see the shortcomings of this approach. Because it sometimes generates incorrect C code that still compiles, we got some really hard-to-find bugs. So we need to examine the generated C code to make sure it does things right. This takes much more time than just writing plain C code myself. Besides, the generated C code is not quite human-readable and debugging becomes a problem. Another issue that’ll hit you is the problems in the library bindings. Though there exists many vala bindings for various C library, their quality is uncertain. Finally, debugging, examing, and fixing the bindings all the time takes even more time and offsets the time saved by using Vala. To sum up, for compiled binary programs, Qt IMHO is a good choice to consider if you don’t hate C++.

PCManFM Qt port is 85% finished now!

dom, 10/03/2013 - 07:59

A picture is worth a thousands words so again let’s see the screenshot first.

This is the Qt port of PCManFM with desktop management feature turned on. The desktop icons and the wallpaper were painted by PCManFM-Qt, just like the gtk+ version of the original PCManFM. The new Qt port is in a pretty good shape now.
Although it’s not yet ready for production use, it’s almost there. About 85% of the planned features are finished.

What already works:
  1. Nearly all folder browsing features
  2. Change icon theme
  3. Preferences dialog (most options work)
  4. Load/save settings
  5. Single instance + dbus service
  6. Command line options
  7. Desktop icon manager: enable with “pcmanfm-qt –desktop”. You can add “pcmanfm-qt –desktop” to the startup script of your desktop environment/window manager.
  8. Change wallpapers via “Desktop Preferences” dialog
  9. Mount remote filesystems and removable devices (requires gvfs)
  10. Split into pcmanfm-qt and libfm-qt library.
  11. Install libfm-qt header files to /usr/includ/libfm-qt along with a pkgconfig file, so later libfm-qt can be used in other Qt programs
  12. Most file operations, move/copy/symlink/trash/rename, change file attributes in the file properties dialog.
  13. Basic drag and drop support (very basic)

Things which do not work or are still work in progress:

  1. Create new folders/files
  2. Edit bookmarks
  3. Auto-mount/auto-run for removable devices
  4. No thumbnail support yet. (This may require some changes of the upstream libfm library)
  5. No ABI version (libtool soname not set yet)
  6. No translations yet (Qt Linguist and the *.ts files are hard to work with and lack features I need, I consider using GNU gettext instead)
Also noted that the git repository is now moved to: git://pcmanfm.git.sourceforge.net/gitroot/pcmanfm/pcmanfm-qt The original libfm-qt repo will be removed later. The binary program pcmanfm-qt and the library libfm-qt.so are bundled in the same package. Please help test and give some comments. If anyone is interested in helping the development, patches are welcomed. Thank you!

PCManFM file manager is ported to Qt?

ter, 19/02/2013 - 13:22

No, LXDE will NOT use Qt. Don’t panic!!
It’s just one of my side projects and was an experiment to test how good libfm and Qt are. Since the core library of PCManFM, libfm, is carefully separated from its Gtk+ UI code, theoratically it can be ported to other GUI toolkits. To give it  a test, I played with Qt recently. The result is quite satisfactory and impressive. I must admit that working with Qt is quite pleasant.

Everybody loves screenshots so here is one.

At first glance, this looks like the original GTK+ version very much. Because I choose “Cleanlook” Qt style, it highly resembles Gtk+ “Clearlooks” theme. Besides, I load the “elementary” icon theme. Though it matches the looks and feels of typical Gnome/Gtk+ programs, this is an 100% pure Qt program.

The most interesting and unique part of the PCManFM Qt port are:

  1. No KDE dependency. Really, it’s a lightweight pure Qt4 program.
  2. Almost as fast as the original Gtk+ version. I have not taken any time to do optimization yet. It’s possible to make it faster after optimization.
  3. Uses Libfm + glib/gio, and supports gvfs. So you can mount remote filesystems.
  4. Source code is clean and short, written in C++.
  5. Desktop independent, do not depend on any specific desktop environment (although it uses glib/gio/gvfs, it does not require Gnome)
  6. Built with cmake. No more autotools.
  7. Later, when the APIs becomes stable, I’ll make it two parts, PCManFM main binary and libfm-Qt, which can be used in other pure Qt programs.

For decades, people from the Gnome/Gtk+ camp and the KDE/Qt camp don’t work each other sometimes. Each of them likes to reinvent the wheel and create functionally equivalent programs with different toolkits. The fact is, technology from both camps can be mixed very well. Qt-based UI sit on top of low level platform APIs from Gnome stack is another good option.

PCManFM Qt, when finished, will be a perfect mix of Gnome libraries + Qt-based UI.  I think it’s a good news for who like Qt but don’t want to install KDE.

The source code is available here:
git clone git://pcmanfm.git.sourceforge.net/gitroot/pcmanfm/libfm-qt

It’s still a work in progress and many parts don’t work yet.
If you’re a Qt developer and is interested in helping the development, feel free to contact me.

P.S. Special thanks to KDE developers Aaron Seigo and Will Stephenson. I met them last year during an open source event “COSCUP 2012” in Taipei, Taiwan. They gave some instructions about how to use Qt. Then, I finished the basic skeleton of this port at that night.