Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

user interface - What are the differences between Gtk+ and Qt?

A lot of people seem to have an opinion about which is better. I'm not really asking for these opinions, what I'd like to know are the details: What are the things that make one graphical toolkit different from another, and which of these differences do Qt and Gtk+ have?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can't speak directly to Gtk+, but at my previous job I used Gtkmm, and at my current job I use Qt. Both are C++, so in that regard they are consistent, but Gtkmm is/was only a wrapper to the Gtk+ code, which is in straight C.

At the time I switched jobs, I recall that one of the main differences in the Ui code was how the two toolkits handled layouts. Some parts I thought Gtk did better, some I thought Qt did better. Both let you get your widgets where you want them, eventually.

Debugging with Gtkmm was a bit of a pain, because the classes generally didn't do anything except hold a pointer to a struct and call Gtk+ functions. That extra level of indirection could be annoying.

Qt has more ancillary code that can be useful in various settings, at least compared to the version of Gtkmm that I was using. Things to make threading, inter-process communication, and networking easier are all appreciated when you need to add a new dimension to your program. They also have their containers, if you want to use those, which I think have a saner interface than the STL containers -- but they do about the same thing in the end, so it's a slight advantage.

The signal/slot mechanism between Gtkmm and Qt is different. Qt relies on an extra step in the compile process to generate meta information, which it uses for its signal/slots. An object using signals or slots must inherit from a QObject, and the QObject inheritance must be the first one, with no diamond structure. This makes it difficult to define an abstract interface that emits a signal, for example. On the plus side, they are inherently aware of threading issues, and will convert the signal/slot connection into an event-based connection when necessary. Gtkmm uses SigC signals, which are straightforward C++ classes, and to me appear to be useful in a wider variety of situations. Also, only objects that make a connection need to inherit from the magic base class, as I recall. Plus, since the slots are objects, you can use them as very nice adaptable functor objects as well.

I'm sure there are other differences, but that is what I recall now. Bear in mind my last experience with Gtkmm was about 3 years ago, so some of those items may have changed by now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...