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

Qt-interest Archive, April 2008
an error with QPainter constructor


Message 1 in thread

Hello,
Consider this function:
#include <qapplication.h>
#include <qpainter.h>
#include <qlabel.h>
int main( int argc, char ** argv )
{
    QApplication a( argc, argv );

    QPainter *qpaint = new QPainter(this);        // EERRRROORR

    QPoint *begin = new QPoint(0, 0);
    QPoint *end= new QPoint( 100, 100 );
    QRect frame(*begin, *end);             //it's the surrounding rectangle
    qpaint->drawRect(frame);
    qpaint->drawArc(frame,16*270,90*16);
    qpaint->translate(200,0);
    qpaint->rotate(360);
    qpaint->drawRect(frame);
    qpaint->drawArc(frame,16*270,90*16);    
    return a.exec();
}

I get this error at 
   error C2673: 'main' : global functions do not have 'this' pointers


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Message 2 in thread

The error message is dead-on. Only class instances have this pointers. 
In addition, painting using Qt (and most event driven GUI libraries) 
should normally only be done during paint events.

Assuming you are new to both C++ and Qt programming, I suggest starting 
with tutorial one as shipped with Qt and work your way from there to get 
an overall feel for Qt programming.

Regards,

Marius K.

Mahmood Naderan wrote:
> Hello,
> Consider this function:
> 
>     #include <qapplication.h>
>     #include <qpainter.h>
>     #include <qlabel.h>
>     int main( int argc, char ** argv )
>     {
>         QApplication a( argc, argv );
> 
>         QPainter *qpaint = new QPainter(this);        // EERRRROORR
>      
>         QPoint *begin = new QPoint(0, 0);
>         QPoint *end= new QPoint( 100, 100 );
>         QRect frame(*begin, *end);             //it's the surrounding
>     rectangle
>         qpaint->drawRect(frame);
>         qpaint->drawArc(frame,16*270,90*16);
>         qpaint->translate(200,0);
>         qpaint->rotate(360);
>         qpaint->drawRect(frame);
>         qpaint->drawArc(frame,16*270,90*16);    
>         return a.exec();
>     }
> 
> I get this error at
>    error C2673: 'main' : global functions do not have 'this' pointers
> ** 
> 
> ------------------------------------------------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
> it now. 
> <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
>  >

--
 [ signature omitted ] 

Message 3 in thread

Ok I will read the tutorial. Until then, does this mean the argument "this" is mandatory? if I want to use it in the main then what should I do?

-------------------
Mahmood Naderan



----- Original Message ----
From: Marius Kjeldahl <mariusauto+qtint@xxxxxxxxxxxx>
To: QT mailing list <qt-interest@xxxxxxxxxxxxx>
Sent: Sunday, April 27, 2008 11:47:44 AM
Subject: Re: an error with QPainter constructor

The error message is dead-on. Only class instances have this pointers. 
In addition, painting using Qt (and most event driven GUI libraries) 
should normally only be done during paint events.

Assuming you are new to both C++ and Qt programming, I suggest starting 
with tutorial one as shipped with Qt and work your way from there to get 
an overall feel for Qt programming.

Regards,

Marius K.

Mahmood Naderan wrote:
> Hello,
> Consider this function:
> 
>    #include <qapplication.h>
>    #include <qpainter.h>
>    #include <qlabel.h>
>    int main( int argc, char ** argv )
>    {
>        QApplication a( argc, argv );
> 
>        QPainter *qpaint = new QPainter(this);        // EERRRROORR
>      
>        QPoint *begin = new QPoint(0, 0);
>        QPoint *end= new QPoint( 100, 100 );
>        QRect frame(*begin, *end);            //it's the surrounding
>    rectangle
>        qpaint->drawRect(frame);
>        qpaint->drawArc(frame,16*270,90*16);
>        qpaint->translate(200,0);
>        qpaint->rotate(360);
>        qpaint->drawRect(frame);
>        qpaint->drawArc(frame,16*270,90*16);    
>        return a.exec();
>    }
> 
> I get this error at
>    error C2673: 'main' : global functions do not have 'this' pointers
> ** 
> 
> ------------------------------------------------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
> it now. 
> <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
>  >

--
 [ signature omitted ] 
Message 4 in thread

On Sunday 27 April 2008 12:21:47 Mahmood Naderan wrote:
> Ok I will read the tutorial. Until then, does this mean the argument "this"
> is mandatory? if I want to use it in the main then what should I do?

QPainter draws over some QWidget. In the provided code you have no surface to 
draw on. First you have to create any widget (that would be target window) 
and then draw what you want in it's draw event. You (as prrgrammer) do not 
really know when OS wants your window to be drawn. It might be minimised, 
overlapped or in any other condition. So you have to listen to OS events and 
draw on request.

If you are coding games there is mostly other way to do same thing. Due to the 
fact that game window redraw is more critical than any GUI you do just redraw 
without waiting for OS confirmation. You still do listen to OS events (like 
key press/key release) though.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.