Qt-interest Archive, August 1999
PROGRAMMING WITH QT (ISBN 1-56592-588-2) BUG REPORT
Message 1 in thread
(1) Page 13, line 8
There is not a QLabel constructor like that. You must add a 0 pointer
after the literal "Hello world": new QLabel("Hello world",0);
(2) Page 13, line 13
The Hello World program has a memory leak. QApplication does not delete
the main_widget.
A solution could be to change line 13 to: int rc = myapp.exec(); delete
myapp.mainWidget(); return rc;
(3) Page 20, line 21
Memory leakage error as described in item 2 above.
(4) Page 27, line 34
Memory leakage error as described in item 2 above.
(5) Page 33, line 117
Memory leakage error as described in item 2 above.
(6) Page 183, line 180
Two memory leaks. One is for main_widget, the other is for myvalidator.
Validators are not deleted by widgets to which they are (only) set by
setValidator(). In the constructor of a validator a parent widget may be
given, if this widget is specified, this widget deletes the validator
object.
Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
delete myvalidator; return rc;
(7) Page 243, line 55
Two memory leaks again. One is for main_widget, the other is for
killerfilter. Event filters are not deleted by widgets.
Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
delete killerfilter; return rc;
The author should revise his memory management practices and an extra
chapter "Qt Memory Management" should be added in subsequent editions.
Miklos Nemeth
CTO, IQSOFT
Message 2 in thread
I am a beginner with Qt.
I wrote my first little program with Qt, and it runs fine on a LINUX system.
However on a SGI running IRIX 6.5, I keep getting segmentation faults and/or
bus errors. I have a hunch this may have to do with sloppy memory management
(I am using color tables in my source code), but I might be completely wrong too.
If any of you encountered similar problems in the past and found a solution, I
would appreciate it very much if you could point me in the right direction.
Koen Janssens
Németh Miklós wrote:
>
> (1) Page 13, line 8
> There is not a QLabel constructor like that. You must add a 0 pointer
> after the literal "Hello world": new QLabel("Hello world",0);
>
> (2) Page 13, line 13
> The Hello World program has a memory leak. QApplication does not delete
> the main_widget.
> A solution could be to change line 13 to: int rc = myapp.exec(); delete
> myapp.mainWidget(); return rc;
>
> (3) Page 20, line 21
> Memory leakage error as described in item 2 above.
>
> (4) Page 27, line 34
> Memory leakage error as described in item 2 above.
>
> (5) Page 33, line 117
> Memory leakage error as described in item 2 above.
>
> (6) Page 183, line 180
> Two memory leaks. One is for main_widget, the other is for myvalidator.
> Validators are not deleted by widgets to which they are (only) set by
> setValidator(). In the constructor of a validator a parent widget may be
> given, if this widget is specified, this widget deletes the validator
> object.
> Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> delete myvalidator; return rc;
>
> (7) Page 243, line 55
> Two memory leaks again. One is for main_widget, the other is for
> killerfilter. Event filters are not deleted by widgets.
> Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> delete killerfilter; return rc;
>
> The author should revise his memory management practices and an extra
> chapter "Qt Memory Management" should be added in subsequent editions.
>
> Miklos Nemeth
> CTO, IQSOFT
>
> --
> List archive and information: http://www.troll.no/qt-interest/
Message 3 in thread
On tir, 17 aug 1999, you wrote:
>I am a beginner with Qt.
>
>I wrote my first little program with Qt, and it runs fine on a LINUX system.
>However on a SGI running IRIX 6.5, I keep getting segmentation faults and/or
>bus errors. I have a hunch this may have to do with sloppy memory management
>(I am using color tables in my source code), but I might be completely wrong too.
>
>If any of you encountered similar problems in the past and found a solution, I
>would appreciate it very much if you could point me in the right direction.
>
Quite difficult to spot an error unless some source code is provided :-)
--
[ signature omitted ]
Message 4 in thread
Hello Koen,
It is likely (though far from certain) that this is a compiler
discrepancy. It is not in the C++ standard how data should be
initialized. It has been my experience that g++ initializes data
(ints <- 0, ptrs <- 0, etc). (It is likely that you are using g++ (or
some derivative) while operating on Linux.) The SGI compilers (CC,
DCC) do not perform any initialization. If your IRIX machine also has
g++ installed try it and see if the code works as on Linux. If it
does then it is fairly certain you have an uninitialized pointer
somewhere due to some code that looks something like:
class foo
{
public:
foo();
void method();
bar* p;
};
foo::foo()
{
}
void foo::method()
{
if(p) p->fun();
}
In g++, foo::foo will initialize p to 0, in CC you have no idea
what it may be, and the conditional in the if statement in foo::method
may evaluate to true. To fix the problem write your constructor as
follows:
foo::foo()
: p(0)
{}
Hopefully I have helped,
Mark.
>
> I am a beginner with Qt.
>
> I wrote my first little program with Qt, and it runs fine on a LINUX system.
> However on a SGI running IRIX 6.5, I keep getting segmentation faults and/or
> bus errors. I have a hunch this may have to do with sloppy memory management
> (I am using color tables in my source code), but I might be completely wrong too.
>
> If any of you encountered similar problems in the past and found a solution, I
> would appreciate it very much if you could point me in the right direction.
>
> Koen Janssens
>
>
>
> Németh Miklós wrote:
> >
> > (1) Page 13, line 8
> > There is not a QLabel constructor like that. You must add a 0 pointer
> > after the literal "Hello world": new QLabel("Hello world",0);
> >
> > (2) Page 13, line 13
> > The Hello World program has a memory leak. QApplication does not delete
> > the main_widget.
> > A solution could be to change line 13 to: int rc = myapp.exec(); delete
> > myapp.mainWidget(); return rc;
> >
> > (3) Page 20, line 21
> > Memory leakage error as described in item 2 above.
> >
> > (4) Page 27, line 34
> > Memory leakage error as described in item 2 above.
> >
> > (5) Page 33, line 117
> > Memory leakage error as described in item 2 above.
> >
> > (6) Page 183, line 180
> > Two memory leaks. One is for main_widget, the other is for myvalidator.
> > Validators are not deleted by widgets to which they are (only) set by
> > setValidator(). In the constructor of a validator a parent widget may be
> > given, if this widget is specified, this widget deletes the validator
> > object.
> > Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> > delete myvalidator; return rc;
> >
> > (7) Page 243, line 55
> > Two memory leaks again. One is for main_widget, the other is for
> > killerfilter. Event filters are not deleted by widgets.
> > Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> > delete killerfilter; return rc;
> >
> > The author should revise his memory management practices and an extra
> > chapter "Qt Memory Management" should be added in subsequent editions.
> >
> > Miklos Nemeth
> > CTO, IQSOFT
> >
> > --
> > List archive and information: http://www.troll.no/qt-interest/
>
> --
> List archive and information: http://www.troll.no/qt-interest/
>
Message 5 in thread
We have been experiencing an interesting problem with qt2. The program
coredumps before entering the main(int, char**). When I look at the corefile,
it dumps in the rld stage!!! (That's when the program is trying to link the
various dso's needed to run properly...) Very strange. If you want, I can ask
our systems department the patches they used to fix the problem.
On Aug 17, 1:17pm, Koen Janssens wrote:
> Subject: Re: [SGI Problems?] PROGRAMMING WITH QT (ISBN 1-56592-588-2) BUG
>
> [ plain text
> Encoded with "quoted-printable" ] :
I am a beginner with Qt.
>
> I wrote my first little program with Qt, and it runs fine on a LINUX system.
> However on a SGI running IRIX 6.5, I keep getting segmentation faults and/or
> bus errors. I have a hunch this may have to do with sloppy memory management
> (I am using color tables in my source code), but I might be completely wrong
too.
>
> If any of you encountered similar problems in the past and found a solution,
I
> would appreciate it very much if you could point me in the right direction.
>
> Koen Janssens
>
>
>
> Németh Miklós wrote:
> >
> > (1) Page 13, line 8
> > There is not a QLabel constructor like that. You must add a 0 pointer
> > after the literal "Hello world": new QLabel("Hello world",0);
> >
> > (2) Page 13, line 13
> > The Hello World program has a memory leak. QApplication does not delete
> > the main_widget.
> > A solution could be to change line 13 to: int rc = myapp.exec(); delete
> > myapp.mainWidget(); return rc;
> >
> > (3) Page 20, line 21
> > Memory leakage error as described in item 2 above.
> >
> > (4) Page 27, line 34
> > Memory leakage error as described in item 2 above.
> >
> > (5) Page 33, line 117
> > Memory leakage error as described in item 2 above.
> >
> > (6) Page 183, line 180
> > Two memory leaks. One is for main_widget, the other is for myvalidator.
> > Validators are not deleted by widgets to which they are (only) set by
> > setValidator(). In the constructor of a validator a parent widget may be
> > given, if this widget is specified, this widget deletes the validator
> > object.
> > Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> > delete myvalidator; return rc;
> >
> > (7) Page 243, line 55
> > Two memory leaks again. One is for main_widget, the other is for
> > killerfilter. Event filters are not deleted by widgets.
> > Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> > delete killerfilter; return rc;
> >
> > The author should revise his memory management practices and an extra
> > chapter "Qt Memory Management" should be added in subsequent editions.
> >
> > Miklos Nemeth
> > CTO, IQSOFT
> >
> > --
> > List archive and information: http://www.troll.no/qt-interest/
>
> --
> List archive and information: http://www.troll.no/qt-interest/
>-- End of excerpt from Koen Janssens
--
[ signature omitted ]
Message 6 in thread
Miklos,
Why are you concerned with widgets that aren't deleted
on exit???
The exit(2) call is God's Own Total Destructor. Same for
return from main()... The entire BSS, DATA and TEXT segements
are destroyed. Unix/Win32/CPM/CMS/MVS/Linux -- all perform
this implicitly.
A leak results when a **subroutine or loop** doesn't destruct
allocated resources that are no longer used or needed.
It sounds like you're using Purify without reading the
Purify manual's fine print... ;o)
:P
>-----Original Message-----
>(1) Page 13, line 8
>There is not a QLabel constructor like that. You must add a 0 pointer
>after the literal "Hello world": new QLabel("Hello world",0);
>
>(2) Page 13, line 13
>The Hello World program has a memory leak. QApplication does not delete
>the main_widget.
>A solution could be to change line 13 to: int rc = myapp.exec(); delete
>myapp.mainWidget(); return rc;
>
>(3) Page 20, line 21
>Memory leakage error as described in item 2 above.
>
>(4) Page 27, line 34
>Memory leakage error as described in item 2 above.
>
>(5) Page 33, line 117
>Memory leakage error as described in item 2 above.
>
>(6) Page 183, line 180
>Two memory leaks. One is for main_widget, the other is for myvalidator.
>Validators are not deleted by widgets to which they are (only) set by
>setValidator(). In the constructor of a validator a parent
>widget may be
>given, if this widget is specified, this widget deletes the validator
>object.
>Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
>delete myvalidator; return rc;
>
>(7) Page 243, line 55
>Two memory leaks again. One is for main_widget, the other is for
>killerfilter. Event filters are not deleted by widgets.
>Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
>delete killerfilter; return rc;
>
>The author should revise his memory management practices and an extra
>chapter "Qt Memory Management" should be added in subsequent editions.
>
>Miklos Nemeth
>CTO, IQSOFT
>
>--
>List archive and information: http://www.troll.no/qt-interest/
>
Message 7 in thread
PAT_WARD@HP-USA-om5.om.hp.com wrote:
> Miklos,
>
> Why are you concerned with widgets that aren't deleted
> on exit???
>
> The exit(2) call is God's Own Total Destructor. Same for
> return from main()... The entire BSS, DATA and TEXT segements
> are destroyed. Unix/Win32/CPM/CMS/MVS/Linux -- all perform
> this implicitly.
>
> A leak results when a **subroutine or loop** doesn't destruct
> allocated resources that are no longer used or needed.
>
> It sounds like you're using Purify without reading the
> Purify manual's fine print... ;o)
>
> :P
>
> >-----Original Message-----
> >(1) Page 13, line 8
> >There is not a QLabel constructor like that. You must add a 0 pointer
> >after the literal "Hello world": new QLabel("Hello world",0);
> >
> >(2) Page 13, line 13
> >The Hello World program has a memory leak. QApplication does not delete
> >the main_widget.
> >A solution could be to change line 13 to: int rc = myapp.exec(); delete
> >myapp.mainWidget(); return rc;
> >
> >(3) Page 20, line 21
> >Memory leakage error as described in item 2 above.
> >
> >(4) Page 27, line 34
> >Memory leakage error as described in item 2 above.
> >
> >(5) Page 33, line 117
> >Memory leakage error as described in item 2 above.
> >
> >(6) Page 183, line 180
> >Two memory leaks. One is for main_widget, the other is for myvalidator.
> >Validators are not deleted by widgets to which they are (only) set by
> >setValidator(). In the constructor of a validator a parent
> >widget may be
> >given, if this widget is specified, this widget deletes the validator
> >object.
> >Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> >delete myvalidator; return rc;
> >
> >(7) Page 243, line 55
> >Two memory leaks again. One is for main_widget, the other is for
> >killerfilter. Event filters are not deleted by widgets.
> >Line 180 should be: int rc = myapp.exec(); delete myapp.mainWidget();
> >delete killerfilter; return rc;
> >
> >The author should revise his memory management practices and an extra
> >chapter "Qt Memory Management" should be added in subsequent editions.
> >
> >Miklos Nemeth
> >CTO, IQSOFT
> >
> >--
> >List archive and information: http://www.troll.no/qt-interest/
> >
You are absolutely right. I am also aware that an exit() (and restart)
solves any memory leakage problem. However, I am disciplined and very
defensive programmer. I am reluctant to accept any bad habit which may lead
to serious problems. Especially memory management is my mania. I think a
tutor should not teach bad habits to learners.
I went on reading the book, and found even more irritating errors (p120,
line 81: the dialog object is never deleted). These example programs have
short life, but let us imagine if someone (beginner in C++ and Qt memory
management) reuses code from this book and includes it into a larger
(mission critical) application.
In C and C++ world we MUST pay extraordinary attention to good memory
management because we are not shielded by garbage collectors.
NM
Message 8 in thread
> These example programs have
> short life, but let us imagine if someone (beginner in C++ and Qt memory
> management) reuses code from this book and includes it into a larger
> (mission critical) application.
That person would be me. From reading the examples, I got the impression
that the Qt library must performing its own garbage collection using
reference counting! Imagine my surprise when I discovered that this was
not the case; by browsing some (very old) messages in the archives of this
list, I gathered that widgets' destructors delete child widgets. The book
says nothing about this (nothing that I can find, anyway). Furthermore,
I can't find anything about this subject in the Qt HTML documentation. I
like Qt, but how can you release a C++ library without saying something in
the documentation about how it handles memory management?
Message 9 in thread
- Subject: Re: PROGRAMMING WITH QT (ISBN 1-56592-588-2) BUG REPORT
- From: Nicolas Hadacek <hadacek@xxxxxxxxxx>
- Date: Wed, 18 Aug 1999 08:20:28 +0200 (CEST)
- Cc: qt-interest@xxxxxxxx
- To: unlisted-recipients:; (no To-header on input)
On Tue, 17 Aug 1999, Benjamin Geer wrote:
> > These example programs have
> > short life, but let us imagine if someone (beginner in C++ and Qt memory
> > management) reuses code from this book and includes it into a larger
> > (mission critical) application.
>
> That person would be me. From reading the examples, I got the impression
> that the Qt library must performing its own garbage collection using
> reference counting! Imagine my surprise when I discovered that this was
> not the case; by browsing some (very old) messages in the archives of this
> list, I gathered that widgets' destructors delete child widgets. The book
> says nothing about this (nothing that I can find, anyway). Furthermore,
> I can't find anything about this subject in the Qt HTML documentation. I
> like Qt, but how can you release a C++ library without saying something in
> the documentation about how it handles memory management?
see the QObject::~QObject documentation ....
you do not have to delete a QObject that has a parent (it gets deleted
with the parent) : very efficient memory management indeed !
Nicolas
Message 10 in thread
Benjamin Geer wrote:
>
> I got the impression
> that the Qt library must performing its own garbage collection using
> reference counting! Imagine my surprise when I discovered that this was
> not the case; by browsing some (very old) messages in the archives of this
> list, I gathered that widgets' destructors delete child widgets. The book
> says nothing about this (nothing that I can find, anyway).
BEFORE YOU WRITE THIS, YOU OUGHT TO READ DALHEIMERS' WARNING AT PAGE 15!
--
[ signature omitted ]
Message 11 in thread
hello .. me again with 2 questions
first, i want to use some QListViewItem with 10 field .. i meen columns,
and the constructor, as far as i see, gives me the possibility to use
maximum 8 columns ... so .... the question is: did someone already do
that, or i must start digging in the dirt ... ( ooops .. in the code :-) )
second, i want to derive a class from QListViewItem that highlights some
cells ... it will be something like that
class myListViewItem : public qlistwievitem {
protected:
// some colours, in fact ... better a colorgroup
virtual int test(int column)=0; // tells me if the column must be
// highlighted or not ( bool )
public:
paintCell(...);
};
and when i want to use a listitem "highlighted"
class myClass : public mylistViewItem {
protected:
int test(int);
};
well ... the problem is with constructors, mylist... is an abstract class,
so i can't declare objects from it ..., but only from myClass
like i said, the problem is with constructors: i guess i can't leave the
default c constructor ... because something like
myClass obj = new MyClass(listview, "one", "two");
it will be rejected, i guess, by the compiler ...
in fact, i am interresed in a method to write as less code as i can ...
but i want to work perfectly too
finally, is legal a code like this:
myClass::myClass(list, str1, str2 ... ):QListViewItem(list, str1, str2...)
10x ...
c u l8r, alligator !
Alex.
----------------------------------------------------------------------------
Alex Cernat : alexc@sundy.cs.pub.ro alexc@alexc.edu.eu.org
Homepage : http://web.cs.pub.ro/~alexc http://i.am/macleod
----------------------------------------------------------------------------
A computer without windows is like a fish without a bicycle
----------------------------------------------------------------------------
Message 12 in thread
On 18 Aug, Alexandru CERNAT wrote:
> hello .. me again with 2 questions
>
> first, i want to use some QListViewItem with 10 field .. i meen columns,
> and the constructor, as far as i see, gives me the possibility to use
> maximum 8 columns ... so .... the question is: did someone already do
> that, or i must start digging in the dirt ... ( ooops .. in the code :-) )
>
....
>
> Alex.
QListViewItem> > ----------------------------------------------------------------------------
> Alex Cernat : alexc@sundy.cs.pub.ro alexc@alexc.edu.eu.org
> Homepage : http://web.cs.pub.ro/~alexc http://i.am/macleod
> ----------------------------------------------------------------------------
> A computer without windows is like a fish without a bicycle
> ----------------------------------------------------------------------------
>
> --
> List archive and information: http://www.troll.no/qt-interest/
hi, alex -
use QListViewItem::setText(int col, const char*) for any col beyond
7. the QListViewItem constructor is just there for convenience.
i'll leave your second question for someone else.
- jd
Message 13 in thread
On Aug 17, 10:10pm, Benjamin Geer wrote:
> Subject: Re: PROGRAMMING WITH QT (ISBN 1-56592-588-2) BUG REPORT
>
> That person would be me. From reading the examples, I got the impression
> that the Qt library must performing its own garbage collection using
> reference counting! Imagine my surprise when I discovered that this was
> not the case; by browsing some (very old) messages in the archives of this
> list, I gathered that widgets' destructors delete child widgets. The book
> --
> List archive and information: http://www.troll.no/qt-interest/
>-- End of excerpt from Benjamin Geer
You would need reference counting if a widget could have multiple parents.
Then, as the last parent gets destroyed, the child widget is destroyed. But
this is not the case, (as far as I know...) qt only lets a widget have one
parent. So reference counting is pointless.
I admit that it REALLY should be stated that the widgets automatically destroy
their children. I was getting a coredump on exit for a while until I figured
this out.....
--
[ signature omitted ]
Message 14 in thread
Hello,
if in doubt, subclass the Widgets you are using, and override the virtual
destructor. put in a ' cout << "~myWidget()" << endl; '. It's a quick and
painless way to see how Qt is cleaning up after itself. Works for me.
Rob Cecil