[Rant] Lost faith in Trolltech
axilmar

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.

Jakub Wasilewski
axilmar said:

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!

SiegeLord

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.

Jakub Wasilewski
SiegeLord said:

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.

axilmar

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.

le_y_mistar

edit

X-G

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...

Arthur Kalliokoski

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...

Wetimer

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.

Thomas Harte

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%".

Thomas Fjellstrom

I've never claimed Qt to be perfect. But it is FAR better than the alternatives imo.

Matthew Leverton

You should see all of the memory leaks in my GUI. 8-)

GullRaDriel

It's a licking library ? ;D

ImLeftFooted

That's a pretty serious error... Even more so because the docs say the proper solution while the reality is very different.

BAF

Ah, trusty old C++. Why the hell are they using char* and TCHAR* anyway? What's wrong with std::string and family?

ImLeftFooted

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. :P

Matthew Leverton
void reverse(char *foo)
{
  char *a = foo, *b = foo + strlen(foo);
  while (a < --b) *a ^= *b, *b ^= *a, *a++ ^= *b;
}

char *reverse_dup(char *foo)
{
  char *d = strdup(foo);
  reverse(d);
  return d;
}

Thomas Harte

Oooh, an in-place reversal. Fancy.

james_lohr

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". :-X Thankfully I was being interviewed by two of them, and the second was an on-the-ball MIT graduate. He quickly backed me up. ;D

ImLeftFooted

The interviewer then responded with "No, not like that. What I meant was, you could swap the pointers instead".

Ah!

Ron Novy

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 :P

#SelectExpand
1* readable way to access arguments passed from C code */ 2#define ARG1 8(%ebp) 3#define ARG2 12(%ebp) 4#define ARG3 16(%ebp) 5#define ARG4 20(%ebp) 6 7/* helper macros in case we ever need to change these */ 8#define _align_ .balign 4, 0x90 9#define FUNC(name) .globl _##name ; _align_ ; _##name: 10#define GLOBL(name) _##name 11 12/* void mem_reverse(char* ptr, unsigned long size); 13 * reverses the block of SIZE bytes pointed to by PTR. 14 */ 15FUNC(mem_reverse) 16 pushl %ebp 17 movl %esp, %ebp 18 pushl %edi 19 pushl %esi 20 pushl %edx 21 pushl %ecx 22 pushl %eax 23 24 /* get input parameters */ 25 movl ARG1, %esi 26 movl ARG2, %ecx 27 std /* %edi gets decremented while %esi gets incremented */ 28 29 /* set %edi to the last byte in the buffer */ 30 movl %esi, %edi 31 addl %ecx, %edi 32 decl %edi 33 34 /* cut %ecx in half */ 35 shrl $1, %ecx 36 37 /* short byte loop or long loop */ 38 cmpl $7, %ecx 39 jle mem_rev_byte_loop 40 41 /* align to %esi bit 0 */ 42 testl $1, %esi 43 jz mem_rev_align0 44 movb (%edi), %al 45 xchgb (%esi), %al 46 stosb 47 incl %esi 48 decl %ecx 49mem_rev_align0: 50 51 /* align to %esi bit 1 */ 52 decl %edi /* adjust %edi since it moves backwards */ 53 testl $2, %esi 54 jz mem_rev_align1 55 movw (%edi), %ax 56 xchgb %ah, %al 57 xchgw (%esi), %ax 58 xchgb %ah, %al 59 stosw 60 addl $2, %esi 61 subl $2, %ecx 62mem_rev_align1: 63 64 /* setup the long loop */ 65 movb %cl, %dl /* save the lower bits of the counter */ 66 shrl $2, %ecx /* divide by 4 */ 67 subl $2, %edi /* adjust %edi since it moves backwards */ 68 69 /* do the loop */ 70mem_rev_long_loop: 71 movl (%edi), %eax 72 bswap %eax 73 xchgl (%esi), %eax 74 bswap %eax 75 stosl 76 addl $4, %esi 77 decl %ecx 78 jnz mem_rev_long_loop 79 80 /* now restore the lower bits we saved in dl and finish off the last bytes */ 81 movb %dl, %cl 82 andb $3, %cl 83 addl $3, %edi 84 85 /* now reverse the bytes */ 86mem_rev_byte_loop: 87 movb (%edi), %al 88 xchgb (%esi), %al 89 stosb 90 incl %esi 91 decl %ecx 92 jnz mem_rev_byte_loop 93 94 /* thats all folks */ 95mem_rev_exit: 96 cld 97 popl %eax 98 popl %ecx 99 popl %edx 100 popl %esi 101 popl %edi 102 movl %ebp, %esp 103 popl %ebp 104 ret

Thomas Fjellstrom

Are the prefix underscores REALLY necessary? Only outmoded systems require them anymore.

axilmar

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:

Quote:

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...

Oscar Giner

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.

Thomas Fjellstrom

Indeed. Using Qt 3 is like continuing to use Windows 98 or 95.

axilmar

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.

Thomas Fjellstrom

You really haven't had much experience with "professionally written code" have you? :P

axilmar

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.

Neil Walker

I'd tell them to ditch C++ and go with vbScript, it's got the function StrReverse already ;)

ImLeftFooted

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!

X-G

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.

Thomas Fjellstrom

But hes acting like its a surprise :o 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.

axilmar said:

Trolltech is supposed to have the best C++ toolkit out there.

What does that tell you about the other toolkits? ;)

axilmar

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.

Quote:

What does that tell you about the other toolkits?

That touching them is a no-no for commercial products?

Thread #601170. Printed from Allegro.cc