ich bin ein qt-änfanger und habe eben mein erste Programm zum Laufen gekrieget .
ich habe ein Sinusfunktion geplottet und hat wunderbar geklappt aber ich hab noch
ein Problem die Window zuschließen. ich versucht mit Hilfe der Methode KeyPressEvent
das Qwidget zu schließen wenn ich Esc-taste drücke :
hier sind Abschnitte von meinem Code
parser.h
Code: Alles auswählen
class Parser: public QWidget{
public:
Parser(int n, QWidget *p=NULL,Qt::WindowFlags f=0);
void setValue( const std::vector<xyvalues> &v);
protected:
virtual void paintEvent( QPaintEvent *ev);
virtual void KeyPressEvent( QKeyEvent *event);
Code: Alles auswählen
void Parser::KeyPressEvent(QKeyEvent* event){
if(event -> Key()== Qt::Key_Escape)
{
event->accept();
close();
}
else{
Parser::KeyPressEvent(event);
}
}
Code: Alles auswählen
QApplication myapp(argc, argv);
xyvalues v;
Parser* pWindow = new Parser (psize);
pWindow->resize(psize,psize);
for(i=0; i<=psize-1; i++){
v.x= i*0.01;
v.y= sin(v.x);
pWindow->setValue(i, v);
}
pWindow->show();
return myapp.exec();
}
Code: Alles auswählen
error: invalid use of incomplete type âstruct QKeyEventâ
/usr/include/qt4/QtGui/qwidget.h:79:7: error: forward declaration of âstruct QKeyEventâ
parser.cpp:549:12: error: invalid use of incomplete type âstruct QKeyEventâ
/usr/include/qt4/QtGui/qwidget.h:79:7: error: forward declaration of âstruct QKeyEventâ
Gruß
seb