tags:

views:

16162

answers:

12

Can someone with extensive experience with both Qt and Java Swing please discuss whether you would use Swing or Qt under Java, and why?

Secondly, what is the business impact of using Qt? Is it reasonably popular or will I have a hard time finding experienced Qt developers? Are there any other business impacts I should be aware of?

UPDATE: I am more interested in the technical and business impacts of Swing vs Qt than the license type/fee since in my case the cost is not a concern.

A: 

I don't know much about swing, but I'd like to react to Adeel's answer regarding Qt.

I don't think finding experienced developer in Qt should be a showstopper : it is very easy and fast to learn Qt. The documentation is very good (that's maybe the best part of Qt : its documentation). IMHO, the Qt community is great and I always found the help needed when I had problems. There is many forums (QtCenter.org, QtForum.org and others) and Trolltech is running a very active mailing list.

Jérôme
I didn't say that it is a showstopper. I just made a point to consider. As the original question mentioned it clearly. Would you down-vote the question too. Kidding.
Adeel Ansari
I didn't made any point regarding documentation. Its great, I must admit. But I forgot to include it, and now I did.
Adeel Ansari
By not so strong community, I meant number of developers, strength. Just go to any Java forum Suns, JavaRanch, Stackoverflow, you would find much help. Of course your list is specific to Qt, where else you will find help then if not there.
Adeel Ansari
+31  A: 

From my experience (one year Qt, several years of Swing).

Swing:

  • Pro:
    • Available on any Java installation. No need to ship any additional code
    • You can write your own custom widgets in Java
  • Contra:
    • Swing is old. There haven't been any updates on the core for years and there won't ever be. If you plan to use Swing, get a good wrapper which will make using Swing much more simple.
    • Swing is hard to understand and use, especially if you're used to UI programming on Windows. (One word: Layouts).
    • Not many powerful widgets in the core set. You'll especially miss a good data grid.
    • For a good look&feel, you need an extra library

Qt:

  • Pro:
    • Comprehensive set of powerful widgets
    • Easy to use and learn
    • Good documentation
    • Good support
    • Active development
    • Uses native widgets and wraps them in a common API across all platforms
  • Contra:
    • Not free for commercial apps (the next version after 4.5 will be LGPL!)
    • You need to ship extra files
    • Qt is written in C++ so you're accessing it via a wrapper library. If you need to implement a complex custom component, things can get hairy.

If you can hire a seasoned Swing developer, give it a try. If you can't and if you have to start from scratch, I suggest against Swing. With Qt, you'll have results within hours and with only little hair pulling. Swing is powerful but it makes no attempt to hide this fact. So you'll find yourself struggling a lot with the API and the defaults which have made sense in 1996 but not anymore today.

Qt has a much steeper learning curve and the API is much more consistent, not to mention that Qt has been improved the last seven years while Swing hasn't (see below). KDE is based on Qt, so there are lot of people out there using it and most of them have only little time (say a few hours here and there) and most can handle Qt after a short time. Which you simply can't say for Swing.

There is a lot of Swing documentation but most only covers the common cases which you can figure out yourself from the Javadoc. If you need something more complex and if you're looking for a bird's eye view, something which gives you a feeling how to combine things to achieve the desired result, I haven't seen anything free and I also can't recommend a book for Swing book because I have stopped looking at them five years ago.

If you look at Java 7, then you'll find that Sun is thinking about working on the Swing API. But: Java 7 is due in two years, there is no commitment for this work items and last but not least: Can you switch to Java 7 when it will be available?

Update: It seems that there won't be any Swing updates for Java 7 after all. Which is a pity. It will leave us with a built-in UI framework from the late 90's which just isn't on top of the times anymore. Being an old Amiga lover, I know how it feels to be abandoned. Thanks, Swing, it's been a nice time.

Aaron Digulla
yeah, because playing with AWT to generate a custom swing component is not a pain.
Ubersoldat
Do you think in Swing we don't have good documentation, good support. Come on, I can come up with 10 or more times more article, tutorials, and books.
Adeel Ansari
Your pro and con stuff is just plain wrong. Swing has a lot more documentation, tutorials and other resources available than there will ever be for QT. Swing is a very flexible framework which allows you to do whatever you want, granted that makes it sometimes a bit complicated. At least it is free.
willcodejavaforfood
I strictly disagree with your pros and cons.
Rastislav Komara
If you want to list pros and cons, you must draw a line somewhere. Yeah, there is a lot of Swing docs. They explain the basic stuff pretty well and then, the air gets thin, quick. So the Qt docs are better.
Aaron Digulla
Swing is flexible but it is also old. That's why I said it's more simple to write custom widgets in Swing *in Java* but Qt is easier to use and understand. From my experience, Swing was good seven years ago and it stayed that way while everything else improved. It's sad :(
Aaron Digulla
Adeel: Ok, I call. give me the URL of a good documentation of JTextPane which explains how to build your own custom editor with syntax hl, spell checking, everything you expect from an editor today.
Aaron Digulla
Completely disagree with all of your Swing cons.
Dan Dyer
Dan: Since you give no reasons, I can only ignore your comment :)
Aaron Digulla
Completely disagree with the entire answer, quite frankly. Details in my answer below.
Software Monkey
It should also be pointed out that Swing widgets are non-native and ass ugly, while Qt widgets are native and beautiful.
Matt Olenik
@Monkey: Please read the question again. This is not an argument against Swing, it's whether he'll likely find developers. Qt is easier to learn than Swing. Plus Swing has been abandoned by Sun, so no updates for Java 7 :(
Aaron Digulla
Qt for Java i.e. Jambi will be officially abandoned as announced by Nokia.
Xolve
@Xolve: Last I heard is that Jambi > 4.5 will become OSS (just like Qt). Please either post a link if you have new information or stop spreading FUD.
Aaron Digulla
FYI: Sun just announced that Swing Application Framework will be part of Java 7.
Gili
Gili: URL? As I heard it, the Swing JSR will be part of the OpenJDK; that doesn't mean it will be in Java 7 :(
Aaron Digulla
To be completely clear, Aaron's update about Swing updates not being issued past Java 7 is purely, simply wrong.The Swing Application Framework (JSR 296) was (IMO) a relatively unambitious compromise effort to provide a unified foundation for building GUI apps, but it only addressed the least interesting plumbing and infrastructure bits (e.g. resource mgmt, bootstrapping, session state, etc). These are all capabilities that every Java app framework (including NetBeans and Eclipse) have done well for *years*, so it's absolutely no loss (again, IMO) that JSR 296 has been shelved.
Chas Emerick
@Chas Emerick: I'm sure most readers will understand that my complaint is that Sun didn't put any effort into Swing for years, not even something as JSR 296. I didn't say anything about JSR 296 itself.
Aaron Digulla
Pavel Minaev
Qt has themes that use native widget drawing mechanisms, even if it does everything else itself, so you can get a native "look" even if the "feel" is implemented in Qt.
ephemient
Aaron, care to comment on this now, one year later and with the changes in QT? Please include a @yar in your answer as I THINK that SO will inform me that way. Thanks!
Yar
@yar: Well ... in one sentence: Swing still sucks a lot, C++ Qt sucks a bit less than last year, Java Qt sucks much more. I haven't used Qt Jambi for anything serious last year, so I can't comment on its state but at least there is an open repository with the code and TrollTech tries to build a community to support it which is more than Sun does for Swing.
Aaron Digulla
Interesting. I got burned answering a few questions SO recently because I said that Swing does NOT give you native look and feel. People said, "get with it! That's no longer true! Swing is now near perfect." I don't know, myself... QT does NOT look like it's got much of a community behind it, judging from random googling.
Yar
Qt is the basis for the Unix GUI environment KDE. Millions of lines of example code. And in my time, maybe 10 years ago, very well and extensively documented in the standard documentation. And the Qt philosophy matches QUI development very well which makes it easy to learn.
extraneon
So uh, if Swing goes away, what else can we use that's "native"? Java would be left with no UI? Would we be stuck with either doing command line or web pages?
Brian Knoblauch
@Brian: My experience is that Qt is much more simple to learn and use then Swing. This doesn't mean you *must not use Swing*. That would be silly. If you have a choice, by all means, use Qt. If you *don't* have a choice (because Qt just isn't available), well, there is no point in arguing which is better, is there?
Aaron Digulla
@Aaron, Qt is fine, except that it's not native. You have to go out of your way to use it. It adds complexity to the project, and I don't even know if it's readily available in a stable version on all the platforms that Swing is. That's my concern right there.
Brian Knoblauch
"If you plan to use Swing, get a good wrapper which will make using Swing much more simple." Which wrappers would you suggest?
Alexey Romanov
+2  A: 

To correct Adeel's comments; You can ship your software commercially - you just have to include the source. There are thousands of developers with Qt experience (KDE). Qt is standard (used by KDE, Nasa, ESA, Adobe, Skype, etc), There's a large Qt community and many books, and the Qt Jambi product is quite new so it's not surprising it's not that well known yet.

Henrik Hartz
And thats what we are talking about, Qt Jambi, not Qt. I admit Qt is quite common, even I am using KDE and quite a no. of applications built on top of Qt.
Adeel Ansari
By Commercially, I meant closed source. I said it wrong, sorry for that. Now correction is made.
Adeel Ansari
+3  A: 

And now Qt will become LGPL as of Qt 4.5, Qt Jambi too ;-)

http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt

Henrik Hartz
+30  A: 

I completely disagree with Aaron Digulla's entire answer as it pertains to Swing.

I have found Swing to be, while not the best design and a little convoluted, reasonably simple and workable, and ultimately quite well thought out. Further, it most definitely is capable of what is required for almost all GUI app's.

Using the native LAF, the application will look and function enough like a native application to receive a passing grade (IMO).

As to the bit about layouts... it's true that the Swing layout's are hardish to use and need nesting (sometimes a fair amount thereof) to get the desired results, but the concept of Layouts are one of the best thing about doing GUI's in Java. Take the time to understand what they do for you and get yourself a good table-based layout (e.g. MatrixLayout, TableLayout, JGoodies FormLayout or MigLayout) which will eliminate 99% of the nesting. A table-based layout will also make your GUI simpler and will make the code better reflect the end result.

So, my advice is that if QT does things in a way in which you would prefer or provides functionality that Swing doesn't, then by all means look into it - provided that you are happy with distributing it's Java and native components with your app, and that it targets the platforms on which you want to run (or may want to run in the future).

Otherwise, it's hard to beat Swing's flexibility and the fact that it's baked into every Java install, and it's ability for you to easily tailor look and behavior.

Oh, and to be fair, I have not looked at QT before - But I have about 6 years of active Swing and AWT development, comprising 1 commercially deployed AWT application and 3 such (non-trivial) Swing applications, plus a number of smaller personal Swing apps.

Software Monkey
Give a try to Qt ;)
Massimo Fazzolari
@Massimo: Last time I check QT for Java was abandoned, or discontinued.
Software Monkey
You should give a try to C++ Qt
Massimo Fazzolari
+14  A: 

Be aware that Qt Jambi will be discontinued shortly. http://www.qtsoftware.com/about/news/preview-of-final-qt-jambi-release-available. My interpretation of this is that following the March 4.5 release, Jambi will be in the same boat as Qt bindings for other languages - up to the community to maintain.

Regarding your questions, I have a few years of Swing experience and I've been working with Qt Jambi for the past month, and I'm pretty mixed.

On one hand, I'm particularly disappointed with Qt's model/view paradigm. Creating an editable tree in Swing, by contrast, using a completely non-Swing model, is a breeze. A couple of hours work. After a week of struggling, I've come to the conclusion that it's just not possible to do such a thing in Jambi 4.4. (Dunno about 4.5) The only solution I can find in Qt is to tie data to the Qt model classes by subclassing QStandardItemModel and QStandardItem. (While QAbstractItemModel is very capable in C++ Qt, it's literally unusable in Qt Jambi.)

On the other hand Qt Jambi gives me access to the amazing QGraphicsView drawing tools, and I don't know of a Java library that can compare. To me, that's the power of Qt Jambi - it gives you access in Java to excellent 2D and GL drawing tools that really aren't available in Java otherwise.

My advice is that if you need to build an application that uses only standard UI widgets like tables, trees, menus, etc., then just use Swing. Layout in Swing is not that hard, really, especially with tools like NetBeans. However, if you need GL or a canvas to paint on, Qt Jambi might be worth looking into.

A: 

I think the most important factor you should consider is that Jambi QT is going to be discontinued from active development.
Swing isn't that of a recent product as well.
You should also definitely consider SWT since in my opinion it generally looks better than Swing.

shoosh
There are not production quality designers for SWT
gotch4
+1  A: 

Pete's comment is right on. For those who need a more powerful swing based toolkit, check out Jide http://www.jidesoft.com/.

A: 

Qt is far better than AWT/Swing. I have been using Qt for past three years and have found absolutely no issues in application development. Compared to Qt(C++), Swing(Java) loses out in run time efficiency and memory efficiency. You may get a lot of Java/Swing resources easily, they are hundred a penny but if you can hire a good Qt/C++ application developer, thats the best choice I say. No offence to Java developers but you have to accept the facts. Qt is available with LGPL licensing.

I did not see anybody mention about its cross platform support and the way it is implemented. There is tremendous advantage for Qt there.

Great documentation, Qt's own intuitive IDE(QtCreator), lotsa examples, and a great and fast growing community out there for support!

Regarding shipping extra files - there are packaging solutions available.

Read more here link text

Deepak
Questionable. How is Qt more cross-platform than Swing? How is LGPL better than "GPL with classpath exception" which Swing ships with?
Gili
A: 

As far as Qt vs Java PDF Deepak has presented, it clearly was written many years ago. Since then Java's virtual machine has improved tremendously, so memory and performance issues are not an issue anymore. The article discusses even the validity of using garbage collector, which I find hilarious!

Next, discussing programming models, signal-slot model has been presented as superiour to MVC, with only measurement being number of the lines of the code required to achieve same effect! What was overlooked in that document is that Java's code is clearly self-documenting, unlike Qt's.

I'm not saying that Qt is worse than Swing. I'm just saying that that document should NOT be used as an argument. First two answers give the best description of both frameworks discussing it's strenghts and weakness alone, without comparing programming models and pulling conlusions out of a thin air.

RockyMM
+1  A: 

Qt Jambi has been picked by community though:

http://qtjambi.sourceforge.net

It is licenced under LGPL and approaching 4.7 release.

Smar