Witam mam taki prosty kod w Qt.
#include <stdlib.h>
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
class mojaklasa : public QWidget
{
public:
mojaklasa();
private:
QPushButton *b1;
};
mojaklasa::mojaklasa()
{
this->setMinimumSize(200,200);
this->setMaximumSize(200,200);
b1=new QPushButton("Hello",this);
b1->setGeometry(20,20,160,60);
}
int main(int argc, char **argv)
{
QApplication a(argc,argv);
mojaklasa w;
w.show();
return a.exec();
}
Chciałbym zdefiniować własne gniazdo. Na poczatek najprostsze z możliwych byleby działało poprawnie. Więc napisałem funkcje która będzie zamykać program (tak wiem ze jest takie gniazdo predefiniowane). Powyższy program przerobiłem tak:
Plik a1.h
#ifndef a1_H
#define a1_H
class mojaklasa : public QWidget
{
Q_OBJECT
public:
mojaklasa();
private:
QPushButton *b1;
public slots:
void MyExitSlot();
};
#endif
Plik a1.cpp
#include <stdlib.h>
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include "4_3.h"
void mojaklasa::MyExitSlot()
{
exit(0);
}
mojaklasa::mojaklasa()
{
this->setMinimumSize(200,200);
this->setMaximumSize(200,200);
b1=new QPushButton("Hello",this); //etykieta i widget macierzysty przycisku
b1->setGeometry(20,20,160,60);
connect(b1,SIGNAL(clicked()),this,SLOT(MyExitSlot()));
}
Plik main.cpp
#include <stdlib.h>
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include "4_3.h"
int main(int argc, char **argv)
{
QApplication a(argc,argv);
mojaklasa w;
w.show();
return a.exec();
}
Po probie kompilacji wysypuja się błędy:
In file included from a1.cpp0:
a1.h9: error: macro names must be identifiers
a1.cpp6: error: ‘mojaklasa’ has not been declared
a1.cpp1: error: ‘mojaklasa’ does not name a type
Proszę o pomoc w definiowaniu własnych gniazd w bibliotece Qt.
Dodam że piszę na ubuntu i kompiluje z konsoli za pomocą poleceń
qmake -project
qmake .pro
make
./