Bug free programming with Qt:



  • Why is Qt a (nearly) bug free API, or better, why are Qt based applications mostly bug free? Shouldn’t you turn your slogan to “Code less, code good, create more”
    In my understanding, most of bug free APIs are dangerous to use: They are bug free until you use them the right way. You need to read in detail the documentation to learn the right way to use it. If you don't strictly respect strange rules you are sure to produce memory leaks or access violation...
    Qt belongs to another category: most of the classes can be safely used “as is”.
    One simple example: You create an orphan widget, you attach it later to a parent widget. The parent takes ownership and you don’t need to worry anymore about the child life cycle.
    Of course Qt also contains some limitations (like the required copy of containers with non-const iterators)
    So, are Qt programmers over experienced, are they all C++ "Harry Potters"? What are the secrets of Qt’s quality programming?
    I miss a place where good practices and good concepts implemented in Qt are listed with all the secrets and magic that lead to that nice result.
    It probably starts with classical C++ recommendations like proper use of private, protected and public structures. Then specific Qt objects may help like QSharedData. You may finally talk about QTestLib.
    The answers are surely spread over the existing documentation.
    Could we however start here to write the list of the good concepts for “bug free programming with Qt”, including the limitations? The list would point to the existing articles of the documentation.
    Does such an article already exists ? Or should this thread lead to a wiki article?

    I hope this can help



  • Umm, are you asking those question, or just bringing it to our knowledge?

    Anyway, without going to specific questions, I think this is just ”good code” against ”bad code”. Think Java as example.



  • Yes it's good code, but I'd like to see written somewhere why is it good code.
    Qt's programmer aren't just skilled programmers. They applly rules, implement concepts, respect good practices.
    I don't know a place that summarizes all those good practices.
    I'm regularly surprised to discover new nice and magic concepts in the documentation.
    It would be nice to have such a list or a general article talking about that and pointing to the existing detailed articles.
    Wouldn't it be worth for the Qt community ?



  • Some of the rules are documented in the "coding style":http://qt.gitorious.org/qt/pages/QtCodingStyle document on gitorious.

    Qt Quarterly 13 had an article about "Designing Qt-Style C++ APIs":http://doc.trolltech.com/qq/qq13-apis.html

    Some more could be found "here":http://www.google.com/search?q=qt+coding+guidelines and "here":http://www.google.com/search?q=qt+coding+style



  • [quote author="laurent bauer" date="1293624799"]I'm regularly surprised to discover new nice and magic concepts in the documentation.[/quote]

    Yeah, I like it too, I'm just learning Qt, and always make things complicated, and then finally find a quite simple, nice, a sophisticated way to make my thing done.

    Volker thanks for links :) I go and look through them immidiately ;)



  • You're welcome. The coding style is more kind-of administrative stuff (and is mostly a matter of taste). The Designing QQ article was quite enlightening. You can see if my own code was written before or after I read that article ;-)



  • While Qt is an excellent piece of software, and one of the most pleasant frameworks I've ever fell in love with, it has a fair share of bugs.



  • I agree: Qt is good, but it not perfect and not nearly bug-free. It does however in most parts provide two IMHO very basic ingredients for making low-bug code:

    It has a clear API (in part thanks to the guidelines Volker linked to) that makes it easy to use right, and hard to use wrong. That may sound trivial, but it is not. A good API encourages using it in such a way that it is hard to go wrong.

    It has generally very good documentation. Good API documentation helps a lot. I frequently stumble on interesting looking libs or code, only to find the majority of the methods and classes are not or hardly documented. That makes using them a PITA.



  • Yes, it's a big help, I've read the gitorious version, and I will the trolltech too later.

    I'm teaching simple C at the University for newbies in this year (I'm an electrical engineer student) and it's very important and quite hard sometimes to teach them how to correctly indentation and style their code. But I'm getting much nicer codes now from them :) So it's worth to tell it a hundred times :)



  • Let's forget the "bug free" and rather talk about "robust" programming instead

    • So, good coding style and conventions contribute to "robust" programming. And we have several links.

    Other possible Qt's contributors to "robust" programming may be:

    • signals & slots : for strong independency of components (+ impossible to crash even if bad coded ?)
    • Implicit sharing and associated objects with reference counting
    • Thread safe objects

    Anything else ?



  • bq. (+ impossible to crash even if bad coded ?)

    That your program does not crash, does not mean it has no bugs :-)

    I agree to the other points though and think that the memory management things are most useful.



  • What do you mean with "memory management things" ? The shared classes ?



  • [quote author="laurent bauer" date="1293645469"]

    • Implicit sharing and associated objects with reference counting
      [/quote]

    yes



  • In the first post, i wrote: "You create an orphan widget, you attach it later to a parent widget. The parent takes ownership and you don’t need to worry anymore about the child life cycle"

    I like this idea : you transfer the management of an object to an object owner. And you don't have to manage it yourself .

    Do you know if this is a concept, a design pattern or anything which has a name?
    Do you know if this coding way is described somewhere?



  • The parent - child relationship, that includes lifetime coupling?

    I would say it's a normal Komposition (UML :-) ).



  • So simple? Well, I feel a bit ridiculous...



  • Must everything be complicated?



  • In a sense, it is just an extension to the standard C++ behaviour to work with pointers (free on destruction) so it is not really a new concept.



  • OK, I guess a widget has a container of children widgets which are destroyed by the parent destructor.
    However, it must be a little bit more tricky because the ownership can be transfered to another parent widget.



  • It's only a QObjectList (which is just a typedef for QList<QObject *>). It is only little more than removing from one and inserting into the other list (and handling layout issues in case of widgets).



  • Yes, it's that simple :) The best things are so simple :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.