I completely lost my trust in Qt these last few days. The amount of hacks and memory errors contained in the version my company had purchased (3.0.5 Windows) is phenomenal. Our client was complaining about crashes, so I had a look at the debug version using a special verification tool, and I found some hair-raising things, totally unexpected from a professional developer like Trolltech.
For example, they have an internal function to convert a string from char* to TCHAR*. This function allocates a TCHAR buffer on the heap, and never frees it! The internal documentation says that each time this function is called, the buffer is reallocated, but this actually does not happen.
I hope they have improved their coding with Qt 4.
For example, they have an internal function to convert a string from char* to TCHAR*. This function allocates a TCHAR buffer on the heap, and never frees it! The internal documentation says that each time this function is called, the buffer is reallocated, but this actually does not happen.
Ohmegod! A memory leak! That never happens to professionals!
Ohmegod! A memory leak! That never happens to professionals!
Considering that Qt is consistently and repeatedly touted as the best thing since sliced bread, such frustration is warranted. As OP shows, it's clearly not... not that that will deter the fanboys that will start trolling this thread imminently.
Considering that Qt is consistently and repeatedly touted as the best thing since sliced bread
I'm pretty sure nobody sane would claim even a moderately complex library (let alone a behemoth like Qt) bug-free.
I'm not a Qt fan (used it quite a few times, liked it, but that's it), but you have to accept that a big piece of software will have bugs. Especially if you are talking about an older version. I might be wrong, but Qt 3.0.5 sounds a bit ancient - Qt4 was released in 2005, I think.
Still, I can understand the pain. It's always annoying when you are looking for an obscure bug in your code, and after seven hours it turns out that something that is usually completely trusted (like the library/compiler) is at fault.
Actually, the example I offered was in a trivial function...a function that simply converted one string to another. The problem was that the function was used all over the place! I simply did not expect something like that from Trolltech.
edit
Converting strings between formats is an extremely ubiquitous piece of code and you'd think they would have discovered any problems -- especially as glaring as this -- early on. Guess they're not the messiah after all...
Maybe the programmers are running wild, and none of them wants to fix bugs in such mundane code, they all want to work on the sexy new stuff. That reminds me of another company too...
Well...
At work we use 3.3, and so 3.0.5 must be really old. While they should have caught that, it might not be the best to judge the quality of the software based on an old release especially one with a zero in the version number.
That said, the code is a bit of a mixed bag. Some of it is rather scary.
That's a shame since in terms of features, QT seems to be substantially ahead of the crossplatform competition. Here on the Mac, recentish applications built with QT use the native widgets and look odd only on account of placement and sizing differences. GTK+ applications run in X11 and look like X11 applications as used by people who left FreeType on the default settings — all the text is spindly and angular and I've no idea what's going on with the glyph placement. And various things seem to be the wrong sizes, such as the window displaying object scale in Inkscape chopping off everything after the first two digits. If objects are full size they are scale "10", if they're halfsize then they're scale "50" and if they're 1/20th size then they're scale "5%".
I've never claimed Qt to be perfect. But it is FAR better than the alternatives imo.
You should see all of the memory leaks in my GUI.
It's a licking library ?
That's a pretty serious error... Even more so because the docs say the proper solution while the reality is very different.
Ah, trusty old C++. Why the hell are they using char* and TCHAR* anyway? What's wrong with std::string and family?
One time during an interview I was asked to do a string reversal in C++. I wanted to laugh at them.
#include <string> #include <algorithm> using namespace std; string revStr(string s) { reverse(s.begin(), s.end()); return s; }
I ended up doing it in C, which is a more challenging project.
Oooh, an in-place reversal. Fancy.
One time during an interview I was asked to do a string reversal in C++. I wanted to laugh at them.
I was asked the same thing in an interview. I also cheated, doing it by pushing the string onto a stack and then popping it off again.
I was then asked for a more efficient way of doing it, to which I answered : "I'd normally do it in plain C by looping half way through the string and swapping values (using a single temporary value), but I chose to use a stack because I'd likely make a silly little error somewhere given the pressure of the interview if I was to do it by looping"
The interviewer replied with: "that's fine, but can you think of an even faster way of doing it?". My answer was : "well, it's probably not more efficient, but there is a nasty little trick using XOR to swap value without using a temporary value".
The interviewer then responded with "No, not like that. What I meant was, you could swap the pointers instead".
Thankfully I was being interviewed by two of them, and the second was an on-the-ball MIT graduate. He quickly backed me up.
The interviewer then responded with "No, not like that. What I meant was, you could swap the pointers instead".
Ah!
Here's the completely over the top and unnecessary GCC style 32-bit assembly version (Compile with "-x assembler-with-cpp" option)... But it's pretty fast on long strings 
Are the prefix underscores REALLY necessary? Only outmoded systems require them anymore.
WTF...The function QString::printf has a static ptr to a QRegExp...I used QString in multiple threads and my program crashed hopelessly and randomly. Then I found the static QRegExp, for which the Qt docs say:
QRegExp uses a static cache and is not threadsafe at all, even if the QRegExp object is protected by using QMutex.
Nice one, Trolltech. QString can effectively be used from the main thread only. Really nice...I now have to replace QString with String everywhere in the project, and code my String class which has the same API as QString.
EDIT:
Many thanks also to the C++ committee for not providing sane string classes along the STL...
Maybe you should upgrade to a newer version of Qt. Qt 3.0.5 is really old (more than 7 years old to be specific). Qt 4 doesn't have any of the issues you've described.
Indeed. Using Qt 3 is like continuing to use Windows 98 or 95.
The project I am currently working on started on 1/1/2008. At that point, Qt 4 was still commercial for commercial use. Since my company had purchased Qt 3, and Qt 3 covered the requirements of the project, it made sense not to spend another 3K$ for Qt 4. Some months later Qt 4 became open source, but then it was late.
The problem described above is unacceptable for professionally written code, no matter how old the version. Trolltech should have not released it, the code wasn't ready. I accept that old libraries may be missing functionality, but I do not accept such big problems. And this problem is huge, a big showstopper.
You really haven't had much experience with "professionally written code" have you?
You really haven't had much experience with "professionally written code" have you?
I know that professionally written code can be sh1tty, I just did not expect Trolltech's code to be that sh1tty. Trolltech is supposed to have the best C++ toolkit out there.
EDIT:
Fixing Trolltech's code has multiple consequences for many people. I put a mutex lock around certain non-thread safe functions, which made the application slower. The tester could not run the application in the test environment, that was a virtual machine, and now he is trying to persuade the system administrator that he needs another brand new PC for the test.
I'd tell them to ditch C++ and go with vbScript, it's got the function StrReverse already
C++ has a reverse function. Not only does it work on strings but it works on any kind of array-like or list-like type!
It doesn't even matter if a lot of professionally written code is shit. That's no excuse. Just because everyone else sucks doesn't mean you should, too.
But hes acting like its a surprise
especially 10 year old code that still had to worry about performance issues from making a class like QString thread safe.
If he's modifying Qt anyhow, it'd probably be better to make it NOT use a static QRegex, than to wrap certain things in a mutex.
Trolltech is supposed to have the best C++ toolkit out there.
What does that tell you about the other toolkits?
If he's modifying Qt anyhow, it'd probably be better to make it NOT use a static QRegex, than to wrap certain things in a mutex.
Not really an option, because QRegex uses a static cache which is not thread safe.
I could fix that as well, but that's not what I am paid to do.
What does that tell you about the other toolkits?
That touching them is a no-no for commercial products?