| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 5 | |
Hi.. How can i make a function return a double array of qpoint ? like this: QPoint pl [ 100 ] [ 200 ] ; pl = theFunction(); Thanks :-) -- [ signature omitted ]
QPoint ** foo( int & rowCnt, int & colCnt ) Or pass it as a reference Void foo( QPoint & pl[ 100 ][ 200 ] ) Or Use QList< QList< QPoint > > which IMHO is preferred, since memory bounds can be checked easier with assertions Scott > -----Original Message----- > From: hihihi [mailto:hihihi@xxxxxxxxxx] > Sent: Tuesday, May 22, 2007 12:04 AM > To: qt-interest@xxxxxxxxxxxxx > Subject: How to make a function return a double array of qpoint ? > > Hi.. > > How can i make a function return a double array of qpoint ? > > like this: > > QPoint pl [ 100 ] [ 200 ] ; > pl = theFunction(); > > > Thanks :-) > > -- > 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 ]
Or use QVector, or one of the other container classes: http://doc.trolltech.com/4.2/containers.html you can easily return those containers by value. Cheers, Peter > -----Original Message----- > From: Scott Aron Bloom [mailto:scott@xxxxxxxxxxxx] > Sent: Tuesday, May 22, 2007 9:20 AM > To: hihihi; qt-interest@xxxxxxxxxxxxx > Subject: RE: How to make a function return a double array of qpoint ? > > QPoint ** foo( int & rowCnt, int & colCnt ) > > Or pass it as a reference > > Void foo( QPoint & pl[ 100 ][ 200 ] ) > > Or > > Use QList< QList< QPoint > > which IMHO is preferred, since memory > bounds can be checked easier with assertions > > Scott > > > > > > > -----Original Message----- > > From: hihihi [mailto:hihihi@xxxxxxxxxx] > > Sent: Tuesday, May 22, 2007 12:04 AM > > To: qt-interest@xxxxxxxxxxxxx > > Subject: How to make a function return a double array of qpoint ? > > > > Hi.. > > > > How can i make a function return a double array of qpoint ? > > > > like this: > > > > QPoint pl [ 100 ] [ 200 ] ; > > pl = theFunction(); > > > > > > Thanks :-) -- [ signature omitted ]
On Tuesday 22 May 2007 09:20, Scott Aron Bloom wrote:
Over the years I have tried many times to understand the pointer stuff.
Part i understand and can use it.
With the stuff below my mind goes blankertyblank
< Information in compatible with current brain. >
< Brain not at home. >
If someone can answer the questions below for me, then i will print the answer
on paper and stick it to the wall, for future reference. :-)
> QPoint ** foo( int & rowCnt, int & colCnt )
const int size1=2000;
const int size2=50;
class Cm {
public:
QPoint **experiment4();
}
QPoint ** Cm::experiment4()
{
QPoint pointsArray[ size1][size2];
return pointsArray;
}
compile error: cannot convert âQPoint (*)[50]â to âQPoint**â in return
How can this be made to work ?
> Or pass it as a reference
>
> Void foo( QPoint & pl[ 100 ][ 200 ] )
const int size1=2000;
const int size2=50;
class Cm {
public:
void experiment3( QPoint[ size1 ][ size2 ] );
}
void Cm::experiment3( QPoint &pl[ size1 ][ size2 ] )
{
}
compiler error: declaration of âplâ as array of references
compiler error: prototype for âvoid Cm::experiment3()â does not match any in
class âCmâ
compiler error: candidate is: void Cm::experiment3(QPoint (*)[50])
How can this be made to work ?
Thank you very much.
--
[ signature omitted ]
> Over the years I have tried many times to understand the pointer
stuff.
> Part i understand and can use it.
> With the stuff below my mind goes blankertyblank
[broken code that has many mistakes deleted]
Which is another reason to leave the (dangerous and complicated) pointer
stuff alone. Use QVector or QList instead, and all will be fine :)
const int size1=2000;
const int size2=50;
class Cm {
public:
QVector<QVector<QPoint> > experiment();
};
QVector<QVector<QPoint> > Cm::experiment()
{
QVector<QVector<QPoint> > pointsArray;
pointsArray.fill(QVector<QPoint>(size2),size1);
return pointsArray;
}
Cm test_cm;
QVector<QVector<QPoint> > table = test_cm.experiment();
QPoint p = table[1][2]; // ok
// gives an error (instead of silently accessing some random memory)
QPoint p2 = table[5000][9000];
Cheers,
Peter
--
[ signature omitted ]
On Tuesday 22 May 2007 12:29, Peter Prade wrote:
> > Over the years I have tried many times to understand the pointer
>
> stuff.
>
> > Part i understand and can use it.
> > With the stuff below my mind goes blankertyblank
>
> [broken code that has many mistakes deleted]
>
> Which is another reason to leave the (dangerous and complicated) pointer
> stuff alone. Use QVector or QList instead, and all will be fine :)
>
> const int size1=2000;
> const int size2=50;
>
> class Cm {
> public:
> QVector<QVector<QPoint> > experiment();
> };
>
> QVector<QVector<QPoint> > Cm::experiment()
> {
> QVector<QVector<QPoint> > pointsArray;
> pointsArray.fill(QVector<QPoint>(size2),size1);
On this line i get:
error: no matching function for call to âQPtrVector<QPtrVector<QPoint>
>::fill(QPtrVector<QPoint>, const int&)â
/usr/lib/qt-3.3/include/qptrvector.h:71: note: candidates are: bool
QPtrVector<type>::fill(const type*, int) [with type = QPtrVector<QPoint>]
gmake[1]: *** [micrometer.o] Error 1
> return pointsArray;
> }
How do i assign one qpoint to the qvectors ?
QVector<QVector<QPoint> > Cm::experiment()
{
QVector<QVector<QPoint> > pointsArray;
for(int count1=0; count1<size1 ; count1++){
for(int count2=0; count2<size2 ; count2++){
// How do i do this ?
pointsArray............ =QPoint( count1, count2);
ï
}
return pointsArray;
}
Thanks.
--
[ signature omitted ]
Hi
IMHO you are better off passing around a QList of QPairs
untested for illustration only:
typedef QPair<QPointF,QPointF> PointPair;
typedef QList<PointPair> PointPairList;
void fooFunction(&PointPairList theList)
{
PointPair myPair;
QPointF x;
QPointF y;
//do stuff to populate x and y....
//
myPair.first=x;
myPair.second=y;
theList.insert(myPair);
//all done
}
I also avoid ** like the plague...
Regards
Tim
Em 22/05/2007, Ãs 08:53, hihihi escreveu:
> On Tuesday 22 May 2007 12:29, Peter Prade wrote:
>>> Over the years I have tried many times to understand the pointer
>>
>> stuff.
>>
>>> Part i understand and can use it.
>>> With the stuff below my mind goes blankertyblank
>>
>> [broken code that has many mistakes deleted]
>>
>> Which is another reason to leave the (dangerous and complicated)
>> pointer
>> stuff alone. Use QVector or QList instead, and all will be fine :)
>>
>> const int size1=2000;
>> const int size2=50;
>>
>> class Cm {
>> public:
>> QVector<QVector<QPoint> > experiment();
>> };
>>
>> QVector<QVector<QPoint> > Cm::experiment()
>> {
>> QVector<QVector<QPoint> > pointsArray;
>> pointsArray.fill(QVector<QPoint>(size2),size1);
>
> On this line i get:
> error: no matching function for call to
> âQPtrVector<QPtrVector<QPoint>
>> ::fill(QPtrVector<QPoint>, const int&)â
> /usr/lib/qt-3.3/include/qptrvector.h:71: note: candidates are: bool
> QPtrVector<type>::fill(const type*, int) [with type =
> QPtrVector<QPoint>]
> gmake[1]: *** [micrometer.o] Error 1
>
>
>> return pointsArray;
>> }
>
>
> How do i assign one qpoint to the qvectors ?
>
> QVector<QVector<QPoint> > Cm::experiment()
> {
>
> QVector<QVector<QPoint> > pointsArray;
> for(int count1=0; count1<size1 ; count1++){
> for(int count2=0; count2<size2 ; count2++){
> // How do i do this ?
> pointsArray............ =QPoint( count1, count2);
>
> ï
> }
> return pointsArray;
> }
>
> Thanks.
>
> --
> 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 ]
> > > Over the years I have tried many times to understand the pointer
> >
> > stuff.
> >
> > > Part i understand and can use it.
> > > With the stuff below my mind goes blankertyblank
> >
> > [broken code that has many mistakes deleted]
> >
> > Which is another reason to leave the (dangerous and complicated)
pointer
> > stuff alone. Use QVector or QList instead, and all will be fine :)
> >
> > const int size1=2000;
> > const int size2=50;
> >
> > class Cm {
> > public:
> > QVector<QVector<QPoint> > experiment();
> > };
> >
> > QVector<QVector<QPoint> > Cm::experiment()
> > {
> > QVector<QVector<QPoint> > pointsArray;
> > pointsArray.fill(QVector<QPoint>(size2),size1);
>
> On this line i get:
> error: no matching function for call to
'QPtrVector<QPtrVector<QPoint>
> >::fill(QPtrVector<QPoint>, const int&)'
> /usr/lib/qt-3.3/include/qptrvector.h:71: note: candidates are: bool
> QPtrVector<type>::fill(const type*, int) [with type =
QPtrVector<QPoint>]
> gmake[1]: *** [micrometer.o] Error 1
dunno why gcc won't find the correct template, for me it compiles (on
MSVC)
you could try to typedef QVector<QPoint> and use that to help the
compiler.
or skip the use of fill and do it this way:
QVector<QVector<QPoint> > Cm::experiment()
{
QVector<QVector<QPoint> > pointsArray(size1);
for(int count1=0; count1<size1 ; count1++){
pointsArray[count1].resize(size2);
for(int count2=0; count2<size2 ; count2++){
pointsArray[count1][count2] =QPoint( count1, count2);
}
}
return pointsArray;
}
Cheers,
Peter
--
[ signature omitted ]
On Tuesday 22 May 2007 14:41, Peter Prade wrote:
> QVector<QVector<QPoint> > Cm::experiment()
> {
> QVector<QVector<QPoint> > pointsArray(size1);
> for(int count1=0; count1<size1 ; count1++){
> pointsArray[count1].resize(size2);
> for(int count2=0; count2<size2 ; count2++){
> pointsArray[count1][count2] =QPoint( count1, count2);
> }
> }
> return pointsArray;
> }
Compile gives two errors.
QVector< QVector < QPoint > > experiment5()
{
typedef QVector<QPoint> VecPoint;
QVector< VecPoint > pointsArray( size1);
for(int count1=0; count1< size1 ; count1++){
pointsArray[count1].resize( size2 );
This line gives this error:
m.cpp:738: error: request for member âresizeâ
in âpointsArray.QPtrVector<type>::operator[] [with type = QPtrVector<QPoint>]
(count1)â, which is of non-class type âQPtrVector<QPoint>*â
for(int count2=0; count2< size2 ; count2++){
pointsArray[count1][count2]= QPoint( count1,count2);
This line gives this error:
m.cpp:740: error: no match for âoperator=â in â*(pointsArray.
QPtrVector<type>::operator[] [with type = QPtrVector<QPoint>](count1) +
((QPtrVector<QPoint>*)(((unsigned int)count2) * 20u))) = QPoint(count1,
count2)â
/usr/lib/qt-3.3/include/qptrvector.h:58: note: candidates are:
QPtrVector<type>& QPtrVector<type>::operator=(const QPtrVector<type>&) [with
type = QPoint]
}
}
return pointsArray;
}
--
[ signature omitted ]
did you #include <QVector> ?
i'm sorry, maybe one of the gcc users can be of greater help to you.
Peter
> -----Original Message-----
> From: hihihi [mailto:hihihi@xxxxxxxxxx]
> Sent: Tuesday, May 22, 2007 6:07 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: How to make a function return a double array of qpoint ?
>
> On Tuesday 22 May 2007 14:41, Peter Prade wrote:
>
> > QVector<QVector<QPoint> > Cm::experiment()
> > {
> > QVector<QVector<QPoint> > pointsArray(size1);
> > for(int count1=0; count1<size1 ; count1++){
> > pointsArray[count1].resize(size2);
> > for(int count2=0; count2<size2 ; count2++){
> > pointsArray[count1][count2] =QPoint( count1, count2);
> > }
> > }
> > return pointsArray;
> > }
>
> Compile gives two errors.
>
> QVector< QVector < QPoint > > experiment5()
> {
> typedef QVector<QPoint> VecPoint;
>
> QVector< VecPoint > pointsArray( size1);
>
> for(int count1=0; count1< size1 ; count1++){
> pointsArray[count1].resize( size2 );
>
> This line gives this error:
>
> m.cpp:738: error: request for member 'resize'
> in 'pointsArray.QPtrVector<type>::operator[] [with type =
> QPtrVector<QPoint>]
> (count1)', which is of non-class type 'QPtrVector<QPoint>*'
>
> for(int count2=0; count2< size2 ; count2++){
> pointsArray[count1][count2]= QPoint( count1,count2);
>
> This line gives this error:
>
> m.cpp:740: error: no match for 'operator=' in '*(pointsArray.
> QPtrVector<type>::operator[] [with type = QPtrVector<QPoint>](count1)
+
> ((QPtrVector<QPoint>*)(((unsigned int)count2) * 20u))) =
QPoint(count1,
> count2)'
> /usr/lib/qt-3.3/include/qptrvector.h:58: note: candidates are:
> QPtrVector<type>& QPtrVector<type>::operator=(const QPtrVector<type>&)
> [with
> type = QPoint]
>
> }
> }
> return pointsArray;
> }
>
>
> --
> 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 ]
On Tuesday 22 May 2007 18:11, Peter Prade wrote: > did you #include <QVector> ? That does not work for me. I use #include <qvector.h> Which QT version are you thinking in ? I use qt 3.3 on fedora core 6. Perhaps 4.x works different ? > > i'm sorry, maybe one of the gcc users can be of greater help to you. Thanks for trying :-) -- [ signature omitted ]
Indeed i was assuming Qt4. I still recommend using the container classes (or you might want to use std::vector from the STL) - i just can't help you with code examples there. Cheers, Peter P.S. It's a good idea to include the Qt version in the subject line! > -----Original Message----- > From: hihihi [mailto:hihihi@xxxxxxxxxx] > Sent: Tuesday, May 22, 2007 6:41 PM > To: qt-interest@xxxxxxxxxxxxx > Subject: Re: How to make a function return a double array of qpoint ? > > On Tuesday 22 May 2007 18:11, Peter Prade wrote: > > did you #include <QVector> ? > > That does not work for me. > I use > #include <qvector.h> > > Which QT version are you thinking in ? > I use qt 3.3 on fedora core 6. > > Perhaps 4.x works different ? > > > > > i'm sorry, maybe one of the gcc users can be of greater help to you. > > Thanks for trying :-) > > > -- > 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 ]
On Tuesday 22 May 2007 18:52, Peter Prade wrote: > Indeed i was assuming Qt4. I am going to look into upgrading from qt 3.3 to qt 4.x -- [ signature omitted ]
If you can do that, I would certainly recommend it simply because I find Qt 4 to be quite intuitive. If it's not, I can certainly try to help you anyway or maybe someone with more experience with Qt 3 can help. Along those lines, I took a peek at the Qt 3.3 API documentation, and it's quite a bit different from Qt 4. What you probably want to use in Qt 3 is QValueVector since the QVector class is, well, not there :) The missing QVector class could possibly explain your problem, though I couldn't say for sure without seeing your whole code file. Good luck with the upgrade! Stuart > On Tuesday 22 May 2007 18:52, Peter Prade wrote: > >> Indeed i was assuming Qt4. >> > > I am going to look into upgrading from qt 3.3 to qt 4.x > > > -- > 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/ > >
Attachment:
Attachment:
signature.asc
Description: OpenPGP digital signature
Message 15 in thread
On Tuesday 22 May 2007 19:21, you wrote:
> What you probably want to use in
> Qt 3 is QValueVector since the QVector class is, well, not there :) The
> missing QVector class could possibly explain your problem, though I
> couldn't say for sure without seeing your whole code file.
QVector is in qt 3.3 called QPtrVector.
If you enter QVector it is automaticaly translated to QPtrVector.
I have relied on this auto translation in all my test of today.
Maybe there goes something wrong.
--
[ signature omitted ]