Well it's strange, but if I put the class def in separate files (say
cannon.h and cannon.cc) than the main function, it works.
Usually, this sort of error appears when a class as virtual methods, but
none is defined in the .cc file, but that doesn't seem to be the case here.
Timothy Miller a ecrit :
Well, since I can't find a diagramming app like I want, I thought I
might start working on one. If I get the ball rolling, perhaps others
will help, and we'll have something workable reasonably soon. If not,
I'll have gotten it done on paper anyhow.
Anyhow, I'm trying to learn Qt, and I'm having a heck of a time. I've
found this tutorial, part of which is at:
http://doc.trolltech.com/3.0/tutorial1-08.html
If I copy their tutorial verbatim, it works fine. But when I try to
use just a piece of it, I get a linker error that I can't figure out.
Googling tells me that there is some virtual function undeclared that
is causing the problem, but I can't figure out how the example is
doing anything different from what I'm doing so... if anyone can help,
PLEASE.
Here's MY code:
#include <qapplication.h>
#include <qpushbutton.h>
#include <qvbox.h>
#include <qwidget.h>
#include <qpainter.h>
class CannonField : public QWidget
{
Q_OBJECT
public:
CannonField( QWidget *parent=0, const char *name=0 );
int angle() const { return ang; }
QSizePolicy sizePolicy() const;
public slots:
void setAngle( int degrees );
signals:
void angleChanged( int );
protected:
void paintEvent( QPaintEvent * );
private:
int ang;
};
CannonField::CannonField( QWidget *parent, const char *name )
: QWidget( parent, name )
{
ang = 45;
setPalette( QPalette( QColor( 250, 250, 200) ) );
}
void CannonField::setAngle( int degrees )
{
if ( degrees < 5 )
degrees = 5;
if ( degrees > 70 )
degrees = 70;
if ( ang == degrees )
return;
ang = degrees;
repaint();
emit angleChanged( ang );
}
void CannonField::paintEvent( QPaintEvent * )
{
QString s = "Angle = " + QString::number( ang );
QPainter p( this );
p.drawText( 200, 200, s );
}
QSizePolicy CannonField::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QVBox box;
box.resize(200, 50);
QPushButton hello( "Hello world!", &box );
hello.resize( 100, 30 );
CannonField cf( &box, "something");
a.setMainWidget( &box );
box.show();
return a.exec();
}
To build it:
qmake -project
qmake
make
What am I doing wrong?
Thanks.
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)