Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, June 2007
Qt 4.3 - qStableSort causes crash on compilation


Message 1 in thread

I have a program that compiles and works perfectly under 4.2 (running FC5) that
uses qStableSort

struct objline
{
  int Mag;
  int AMag;
  double NA;
  double Psize;

  QString Medium;

};   

Class SysParmWin
{
...
static bool ObjLessThan(objline &o1, objline &o2)
};

//
...lots of code ...
   QList <objline> objsort;

//  populate list
   .......
l534:   qStableSort(objsort.begin(), objsort.end(), SysParmWin::ObjLessThan);

However, when I compile using Qt 4.3 & FC 7 - I get the following:
/usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qLowerBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
/usr/include/QtCore/qalgorithms.h:249:   instantiated from ʽRandomAccessIterator qLowerBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:443:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
sysparmWin.cpp:534:   instantiated from here
/usr/include/QtCore/qalgorithms.h:486: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
/usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qUpperBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
/usr/include/QtCore/qalgorithms.h:282:   instantiated from ʽRandomAccessIterator qUpperBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:448:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
/usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
sysparmWin.cpp:534:   instantiated from here
/usr/include/QtCore/qalgorithms.h:507: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
make: *** [obj/sysparmWin.o] Error 1

If I change the qStableSort to qSort - it compiles (and works) perfectly.

Any ideas?

DS
 




      Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com

--
 [ signature omitted ] 

Message 2 in thread

Minimum need for stl style vectors is either an operator =() and/or a
copy constructor (as well as an empty constructor in the case of the
copy constructor). Also, if you're doing sorting, might be worthwhile
implementing an operator <()

David Scriven wrote:
> I have a program that compiles and works perfectly under 4.2 (running FC5) that
> uses qStableSort
>
> struct objline
> {
>   int Mag;
>   int AMag;
>   double NA;
>   double Psize;
>
>   QString Medium;
>
> };   
>
> Class SysParmWin
> {
> ...
> static bool ObjLessThan(objline &o1, objline &o2)
> };
>
> //
> ...lots of code ...
>    QList <objline> objsort;
>
> //  populate list
>    .......
> l534:   qStableSort(objsort.begin(), objsort.end(), SysParmWin::ObjLessThan);
>
> However, when I compile using Qt 4.3 & FC 7 - I get the following:
> /usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qLowerBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
> /usr/include/QtCore/qalgorithms.h:249:   instantiated from ʽRandomAccessIterator qLowerBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:443:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
> sysparmWin.cpp:534:   instantiated from here
> /usr/include/QtCore/qalgorithms.h:486: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
> /usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qUpperBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
> /usr/include/QtCore/qalgorithms.h:282:   instantiated from ʽRandomAccessIterator qUpperBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:448:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
> sysparmWin.cpp:534:   instantiated from here
> /usr/include/QtCore/qalgorithms.h:507: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
> make: *** [obj/sysparmWin.o] Error 1
>
> If I change the qStableSort to qSort - it compiles (and works) perfectly.
>
> Any ideas?
>
> DS
>  
>
>
>
>
>       Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>   


-- 
 [ signature omitted ] 

Message 3 in thread

David Scriven wrote:
> I have a program that compiles and works perfectly under 4.2 (running FC5) that
> uses qStableSort

> Class SysParmWin
> {
> ...
> static bool ObjLessThan(objline &o1, objline &o2)
> };
> 

Hi David,
Try defining objLessThan to take const references, like this:

static bool ObjLessThan(const objline &o1, const objline &o2)

The reason for this is that qStableSort in 4.3 uses qLowerBound and 
qUpperBound internally, which doesn't allow using a LessThan that takes 
its arguments by non-const reference.

Morten

--
 [ signature omitted ] 

Message 4 in thread

Presumably the ObjLessThan is equivalent to the <() operator.
It compiled and worked perfectly in 4.2, and it compiles
and works in 4.3 with qSort, so either the fact that it works in
these two cases is an error, or the requirements are not as
strict as you've stated.

I'm confused - if it failed always - both 4.2 & 4.3 - both 
qStableSort & qSort - then I'd understand, but the inconsistency
is very puzzling.

----- Original Message ----
From: Bill KING <bill.king@xxxxxxxxxxxxx>
To: David Scriven <davidwriter@xxxxxxxxx>
Cc: qt-interest@xxxxxxxxxxxxx
Sent: Thursday, June 21, 2007 7:58:39 PM
Subject: Re: Qt 4.3 - qStableSort causes crash on compilation

Minimum need for stl style vectors is either an operator =() and/or a
copy constructor (as well as an empty constructor in the case of the
copy constructor). Also, if you're doing sorting, might be worthwhile
implementing an operator <()

David Scriven wrote:
> I have a program that compiles and works perfectly under 4.2 (running FC5) that
> uses qStableSort
>
> struct objline
> {
>   int Mag;
>   int AMag;
>   double NA;
>   double Psize;
>
>   QString Medium;
>
> };   
>
> Class SysParmWin
> {
> ...
> static bool ObjLessThan(objline &o1, objline &o2)
> };
>
> //
> ...lots of code ...
>    QList <objline> objsort;
>
> //  populate list
>    .......
> l534:   qStableSort(objsort.begin(), objsort.end(), SysParmWin::ObjLessThan);
>
> However, when I compile using Qt 4.3 & FC 7 - I get the following:
> /usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qLowerBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
> /usr/include/QtCore/qalgorithms.h:249:   instantiated from ʽRandomAccessIterator qLowerBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:443:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
> sysparmWin.cpp:534:   instantiated from here
> /usr/include/QtCore/qalgorithms.h:486: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
> /usr/include/QtCore/qalgorithms.h: In function ʽRandomAccessIterator QAlgorithmsPrivate::qUpperBoundHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ:
> /usr/include/QtCore/qalgorithms.h:282:   instantiated from ʽRandomAccessIterator qUpperBound(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:448:   instantiated from ʽvoid QAlgorithmsPrivate::qMerge(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = const objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:467:   instantiated from ʽvoid QAlgorithmsPrivate::qStableSortHelper(RandomAccessIterator, RandomAccessIterator, const T&, LessThan) [with RandomAccessIterator = QList<objline>::iterator, T = objline, LessThan = bool (*)(objline&, objline&)]ʼ
> /usr/include/QtCore/qalgorithms.h:209:   instantiated from ʽvoid qStableSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<objline>::iterator, LessThan = bool (*)(objline&, objline&)]ʼ
> sysparmWin.cpp:534:   instantiated from here
> /usr/include/QtCore/qalgorithms.h:507: error: invalid initialization of reference of type ʽobjline&ʼ from expression of type ʽconst objlineʼ
> make: *** [obj/sysparmWin.o] Error 1
>
> If I change the qStableSort to qSort - it compiles (and works) perfectly.
>
> Any ideas?
>
> DS
>  
>
>
>
>
>       Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>   


-- 
 [ signature omitted ]