ich habe auf einer QMainWindow ein QPushButton der zur Laufzeit bei einem click einen zweiten PushButton (pb1) erstellt. Bei Klick auf pb1 soll ein Label erstellt werden. Aber die Funktion wird nicht aufgerufen. Ich hab alle möglichen Variationen ausprobiert, aus Forensuche und Qt Tutorials konnte ich auch keine zielführenden Infos gewinnen.
Der Header:
Code: Alles auswählen
#ifndef SCROLLBOOK_H
#define SCROLLBOOK_H
#include <QtGui/QMainWindow>
#include "ui_scrollbook.h"
#include <QtGui>
class ScrollBook : public QMainWindow
{
Q_OBJECT
public:
ScrollBook(QWidget *parent = 0);
~ScrollBook();
private:
QLabel *label1;
QPushButton *pb1;
Ui::ScrollBookClass ui;
private slots:
void on_pushButton_clicked();
void on_pb1_clicked();
};
#endif // SCROLLBOOK_HCode: Alles auswählen
#include "scrollbook.h"
#include "ui_scrollbook.h"
#include <QtGui>
ScrollBook::ScrollBook(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
setFixedSize(200, 200);
}
ScrollBook::~ScrollBook()
{
}
void ScrollBook::on_pushButton_clicked()
{
pb1 = new QPushButton(tr("Label erzeugen"), this);
pb1->setGeometry(62, 80, 75, 30);
pb1->setFont(QFont("Times", 12, QFont::Bold));
pb1->show();
connect(this, SIGNAL(clicked()), pb1, SLOT(clicked()));
}
void ScrollBook::on_pb1_clicked()
{
label1 = new QLabel(tr("ein Label ohne Sinn und Zweck"), this);
label1->setGeometry(62, 120, 120, 25);
label1->setFont(QFont("Times", 14, QFont::Bold));
label1->show();
}