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

Qt-interest Archive, May 2007
How to make a function return a double array of qpoint ?

Pages: Prev | 1 | 2 | Next

Message 16 in thread

I'm diving in the middle of this, so I apologize if I have missed
something and am asking you to repeat steps.

I looked over your example code and wrote up a small example to test on
my own system.  I ran the following small program and it worked exactly
as expected:

#include <iostream>
#include <QVector>
#include <QPoint>

using namespace std;

int size1 = 10;
int size2 = 20;

QVector<QVector<QPoint> > experiment()
{
        typedef QVector<QPoint> VecPoint;
        QVector<VecPoint > 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;
}

int main(int argc, char** argv)
{
        QVector<QVector<QPoint> > mainPointsArray;

        mainPointsArray = experiment();

        for (int i = 0; i < mainPointsArray.size(); i++) {
                for (int j = 0; j < mainPointsArray[i].size(); j++) {
                        cout << mainPointsArray[i][j].x() << ", "
                                << mainPointsArray[i][j].y() << endl;
                }
        }

        return 0;
}

The system I just tested on is using gcc 3.4.4 and Qt 4.2.3.  If you
create a separate file with only the above code in it (using the
appropriate headers for Qt 3, of course), do you still encounter
compiler errors?

Stuart
> 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/
>
>   


Attachment:

Attachment: signature.asc
Description: OpenPGP digital signature


Message 17 in thread

On Tuesday 22 May 2007 18:53, you wrote:

> I'm diving in the middle of this, so I apologize if I have missed
> something and am asking you to repeat steps.

No problem, all help is welcome.

> #include <QVector>
> #include <QPoint>

This does not work in qt 3.3.
Which makes it more likely i should upgrade to qt 4.x

Thanks.

--
 [ signature omitted ] 

Message 18 in thread

> This does not work in qt 3.3.
> Which makes it more likely i should upgrade to qt 4.x

if you don't have to port existing code, it's no question you should
upgrade to Qt4. Qt3 reaches the end of its lifecycle this July.

Even if you have to port some code, it's probably the better decision
long-term.

Cheers,
Peter

--
 [ signature omitted ] 

Message 19 in thread

On Tuesday 22 May 2007, hihihi wrote:
> 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 ?

<sarcasm - joke>
this is a C question and this is a Qt-C++ mailing list
</sarcasm - joke> ;-)

>
> > 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 ] );

this sould be 
	void experiment3(QPoint[size1][size2]& pl);


> }
>
> 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])
>

Anyway if you need to stick with pointers (maybe for performance gain after 
profiling has told you so) you should consider using shared pointers ( 
shared_ptr or shared_array from boost.org) and also typedefing the array 
types for clarity and future changes.

If you can, or if you haven't profiled your application yet you should stick 
with std::vector or QList witchever you like, it will surly spare you a lot 
of time/stress/frustration. 


-- 
 [ signature omitted ] 

Attachment: pgpJ1lTfsqx8a.pgp
Description: PGP signature