Code: Alles auswählen
//Button.h
#ifndef Button_h
#define Button_h
#include<QWidget>
class QPushButton;
class Button:public QWidget
{
private:
QPushButton *button;
const short value;//ein Button hat eine Zahl drauf(is für nen rechner)
public:
Button(int value,int x,int y,int w,int h, QWidget*parent=0);
short getValue() const;
};
#endif
Code: Alles auswählen
//Button.cpp
#include"Button.h"
#include<QPushButton>
#include<QVBoxLayout>
Button::Button(int value,int x,int y,int w,int h, QWidget*parent):
QWidget(parent),value(value)
{
char*name=new char;
name[0]=static_cast<char>(value+static_cast<int>('0'));//improvisiert
button=new QPushButton(name,0);
QVBoxLayout*layout=new QVBoxLayout;
layout->addWidget(button);
setLayout(layout);
this->setGeometry(x,y,w,h);
}
short Button::getValue() const
{
return this->value;
}
Code: Alles auswählen
//main.cpp
#include<QApplication>
#include<QWidget>
#include"Button.h"
int main(int argc,char*argv[])
{
QApplication *app=new QApplication(argc,argv);
QWidget* MyWindow=new QWidget;
MyWindow->setFixedSize(100,100);
Button myButton(1,10,10,20,20,MyWindow);
MyWindow->show();
return app->exec();
}
Ich schätze der Fehler liegt im Konstruktor oder es ist ein denkfehler