tags:

views:

2321

answers:

10

I heard Qt API is written in pretty outdated C++ language. Is it true?
Are there any plans to make it use more modern C++ language? Are there any official information on this?

Are there any projects with the aim to wrap current Qt API constructs with more modern C++?

UPDATE
That's more to this question than templates and that's not the question only about the current state of affairs (that's why I tagged it with the future tag).

UPDATE
I'm especially concerned with Qt API as this is what users of this framework work with.
Using modern C++ language in API makes it more robust, flexible and easier to use.
What kind of C++ is used inside Qt is far less important to me.

+25  A: 

Qt is known not to use templates, one very useful modern c++ feature. But that does not mean that there is a need for a wrapper to Qt's API. Qt uses in-house precompilers to address the same issues. Some don't like this approach, but Qt's API is very simple and efficient, and i don't believe there is a real need to modernize it. In particular, signals&slots, a very impressive feature from Qt, can be achieved using templates (see boost.signals library), but the way Qt has implemented it is still much more efficient.

I'd say "don't worry and use Qt as is".

EDIT: Sorry i forgot about template containers provided with Qt. But still, Qt's API makes very little use of template classes. This does not mean that they don't use them inside Qt though or that their way of coding is obsolete.

Boost.Signals are probably more powerful than Qt signals/slots but, as far as i can tell, there is no arguing about which is simpler to use. One very convincing implementation of the KISS principle.

Benoît
I was going to write something along these lines myself, but you beat me to it and with great skill too :)I could not agree more.
shylent
Don't forget Qt's generic templated containers http://doc.trolltech.com/4.5/containers.html :)
Johannes Schaub - litb
Life without templates really isn't so bad. At least your code is easier to read and compiles smaller.
Crashworks
@Benoit I always worry about everything that isn't being updated because of compatibility with older versions. And templates is not the only feature C++ got since Qt was designed. There are plenty of them and I'm sure Qt could make a good use of each one of them.
Piotr Dobrogost
@litb "These container classes are designed to be lighter, safer, and easier to use than the STL containers." sounds a little bit scary to me. I'm always scary when someone outside of the standard committee is trying to make something better than the committee did. The last thing I want is to have to learn yet another container classes. And I'm pretty sure without even looking at them they're not better than STL ones... :)
Piotr Dobrogost
Personally I much prefer Boost.Signals to Qt signals. Boost.Signals can hook into basically anything that's callable, provide compile-time checking of types, and I find treating the signal emitter as its own object to be more intuitive. Qt's signal system is just so restricted in comparison. I find myself only using Qt signals for ui related signal handling and using Boost signals for pretty much everything else because they allow for a much more flexible system. Especially when you have code-bases for which you cannot introduce dependencies on Qt.
@piotr: I would always be very wary of _anything_ designed by a committee. Look at Ada.
PiedPiper
I find STLs coding style disturbing and Qt's beautiful. Also their containers contain more functionality and are way more convenient. E.g. in terms of converting from one to the other, or debugging.
Ronny
Qt also uses c++ namespaces at some places. like for phonon
Johannes Schaub - litb
Johannes Schaub - litb
They use some templates, for example QFuture in qt concurrent.
@litb How would you comment on stbuton's comment?
Piotr Dobrogost
Piotr, i'm sorry i've not much experience with Qt to be able to comment on him. i just made some small qt3 app and looked into the container docs to make my point :)
Johannes Schaub - litb
@Benoît How would you comment on andre's comment about Qt using templates?
Piotr Dobrogost
@Piotr: I don't exactly know what figures would prove Andre right or wrong. I edited my original answer to mention containers, which i personally dislike. Apart from them, i still consider that there are few template classes in Qt's API (261 files out of 2053 in qt's api contain the "template" keyword).
Benoît
+2  A: 

I, too, don't like the way Qt adds voodoo magic to C++. It uses so many macros that it awfully reminds me of C. At the moment, there is nothing to indicate that Qt would be kinder to C++ features in the future. I would really like to see it be more like C++ and not a language of its own (e.g. Why do we need std::vector<> and QVector<>? Or Qt signals, Boost.Signals and sigc++?)

fengshaun
I would like to point out that none of the signal methods you mention are currently part of C++ or its standard library. They're all 3rd party libraries. As for QVector, it's a vector container with a Qt style API. Qt's API is one of its biggest selling points, so providing container classes with a familiar API only makes sense for them.
Parker
@Parker STL and boost are ones of the biggest selling points of C++ nowadays. Shouldn't Qt design their API to be compatible with them and not invent yet another one?
Piotr Dobrogost
@Piotr Qt containers are STL compatible. Qt is a major selling point for C++, why did Boost invent their own signal/slot mechanism? ;) Diversity is a good thing.As for Qt signals and slots being compatible with Boost's, keep in mind that Qt *invented* signals and slots back in 1994 when templates weren't an real option. Nowadays Boost signals might be the better implementation, but Qt has a lot of customers with a lot of code written using the existing system. They might look at using templated signals for Qt5, but until then their hands are tied. http://doc.qtsoftware.com/4.5/templates.html
Parker
I don't know that there's nothing to indicate Qt will use future C++ features... sometimes there's the opposite. Take, for example, their addition of 'foreach' a few years ago, well before most compilers had any support for it.
Caleb Huitt - cjhuitt
@Parker "Qt is a major selling point for C++" that's pretty bold statement. I'm sure it's false too.
Piotr Dobrogost
@Parker "Qt has a lot of customers with a lot of code written using the existing system. They might look at using templated signals for Qt5, but until then their hands are tied." Their hands are not tied. They can introduce new ways of doing things in addition to existing ones.
Piotr Dobrogost
There are specific reasons Qt has not switched to using templates for signals and slots. Among other things they want runtime reflection beyond what basic C++ provides. It's not necessarily true that Boost's signals are better: there are distinct tradeoffs between the implementations. Parker's link above is worth reading: even if you don't end up agreeing with the choice it explains their rationale clearly.
quark
The only macro that I use in C++/Qt is Q_OBJECT (to indicate that this class users signals/slots and should be processed by Qt's moc). What other macros does it use then, according to you?
Wim Leers
+1  A: 

Qt is a library and needs to support a wide range of compilers. It still supports MSVC6, e.g. (I think Qt Software is phasing out support for this, though). This limits the more modern C++ features, Qt is able to use.

But this does not mean that you can't use them in your Qt program.

ashcatch
Supporting older compilers doesn't prevent from using modern C++ on compilers supporting it. All that is needed is information about which platforms given construct is supported on. Not using current C++ in a C++ framework discourages from using such a framework. What's more there is a big chance someone will come up with a different one with similar functionality but written in modern C++ and thus much cleaner and easier to use.
Piotr Dobrogost
One of the most valuable aspect of any C++ framework is how well it can be used with the standard library. Inventing new containers is not the way any C++ framework should go.
Piotr Dobrogost
+11  A: 

Qt sources contain the pattern "template <" 1280 times in src/corelib alone. I fail to see how this can be mistaken as "Qt is known not to use templates"

You are right. They do not use templates for their signal/slot event system, but they do use templates plenty...
JimDaniel
+1 I could need a clarification, too.
soulmerge
+3  A: 

I really don't like the way Qt managed to implement its signals/slots mechanism. Their 'moc' precompiler really smells like a hack to me, and it doesn't even support standard C++.

I think it would be great if Qt could modernize itself to use at least the STL classes. What would be really awesome would be for Qt to use Boost whenever possible (especially Boost.Signals).

Martin Cote
I don't see Qt using STL any time soon. Now that Nokia owns Trolltech the drive is towards Nokia mobile platforms and Symbian isn't exactly friendly with the C++ standard.
TrayMan
@OP Totally agree.
Piotr Dobrogost
@TrayMan Very sad... :(
Martin Cote
@TrayMan: Do you have the proof that Qt is driven toward Nokia mobile platforms *only* ?
Ariya Hidayat
+16  A: 

Qt uses modern variants of the C++ language - currently C++98, and yes Templates are also used where it's appropritate. Qt has some support for STL. See e.g. http://doc.trolltech.com/4.5/containers.html - and convenience functions for e.g. std::string. It's all in the docs: http://doc.trolltech.com/4.5/ ;) The question about templates vs moc is one we get so often we have added it to our documentation; http://doc.trolltech.com/4.5/templates.html

Henrik Hartz
@Henrik Thanks for your comment. I think most arguments against templates in the article you pointed out are very weak. Can you point us to articles critical of the one you showed?
Piotr Dobrogost
@Henrik By the way; SO is becoming very popular among developers. Do you think someone from Qt team could monitor and answer Qt questions here?
Piotr Dobrogost
@Piotr There are a number of various sources that you will find by googling, but it's a consistent complaint that we have chosen to document in that article :)
Henrik Hartz
@Piotr there are now three people active on SO, let's hope the popularity spreads inside Qt Software ;)
Henrik Hartz
+8  A: 

Unlike Boost.Signals, Qt's implementation of signals/slots is thread-safe via the use of queued connections. On May 2nd, 2009, however, Boost.Signals2 was released and brought with it the much-desired thread-safety. From the developer point of view, Qt's implementation of signals/slots is much easier to use, mostly due to the fact that it does not use templates. For an in depth read of why Qt uses moc instead of templates for signals and slots, here's a page from their documentation.

For those wondering why Qt has its own set of container classes, I'm pretty sure that the main motivation was to offer implicit sharing. All of the container classes are implicitly shared, so whenever a QList is copied, only a pointer to the data is copied. See here for more information on shallow copying within Qt.

Krsna
@Krsna See http://www.gotw.ca/publications/optimizations.htm where Herb Sutter shows why implicit sharing aka shallow copying aka COW (copy-on-write) is bad in a multithreaded environment.
Piotr Dobrogost
@Piotr Interesting read and good point. According to Trolltech (http://doc.trolltech.com/4.5/threads.html#threads-and-implicit-sharing), Qt 4's implicitly shared classes are re-entrant, meaning that a class's member functions can be called simultaneously from different threads, as long as each of those threads has its own instance of the class.
Krsna
+4  A: 

To directly answer your question, Qt's API is comprehensive. I'm pretty sure they'll come out with a QApp::ParkMyCar() function some time. They sometimes implement multiple ways of doing the same thing, with different positions on efficiency vs ease of use. Check out their (excellent) documentation. It is as comprehensive, and has saved my ass more than once.

From what I've seen of the Qt source code, the code is highly efficient.
Take a look at the features in the install configuration - you can turn on/off support for various features (including STL, threading and even the GUI). Further, when the Trolls made Qt 4 ground-up, they did not trade off features against code-jazz -they just delivered more of both. Given the quality of their programmers and their way of updating major versions, I don't think we need to worry about Qt (or parts) getting outdated.

Qt's target market (for desktops) is the MamaPapa company that makes Hello Kitty desktop alarm clocks, and wants to Code once and rest assured that it runs on all "sane" systems - Windows 98 and above, popular Linux distros and Mac OS X. This means pandering to the LCD of all the main compilers in each kind of system. If this means keeping template-wizardry in their code to a minimum, so be it.

I was not asking how comprehensive Qt's API is.I was not asking how efficient their code is.Supporting DOS based Windows 98 in the year 2009 is insane and makes much harm to majority of users...You don't compete with the .NET by supporting ancient systems...
Piotr Dobrogost
Well, actually you do. If you have to compete with a 400 pound gorilla, you live of the scraps, you don't face him head on.
Marco van de Voort
+4  A: 

Throughout the Qt 4.x lifetime, I doubt that it makes sense to rewrite parts of Qt to use e.g. "more modern" C++. This is because of the premise that all releases in the same major version of Qt should still be binary compatible. We also can not just obsolete or deprecate classes that the customers still use (although it is perfectly fine to introduce new stuff, even for a limited set of supported compilers).

If finally Qt 5 is almost out of the door, and the modern C++ constructs and features are finally available in the targeted supported platforms and compilers, and doing so will help C++ developers and customers to write better and more powerful code, then why not?

Ariya Hidayat
A: 

Qt is a very smartly created library. The more I use Qt the more I like it! Not like MFC ;)! So just enjoy using it, and don't worry how it is implemented. Of coure if you do not have a better alternative.

Narek