Connection QPushButton to a Function in main.cpp



  • Hello,
    I have a main.cpp with a window and also a QPushButton.

    @#include <QApplication>
    #include <QPushButton>
    #include <QtWidgets>
    #include <kfz.h>
    #include <diagramm.h>

    int main(int argc, char* argv[])
    {

    QApplication app(argc, argv);
    
    QWidget *window = new QWidget;
    QGridLayout *box = new QGridLayout(window);
    

    ...

    QObject::connect(button, SIGNAL(clicked()),&app, SLOT(onbuttonclicked()));

    ...
    @
    I have another class Diagramm.cpp
    @#include "diagramm.h"
    #include "ui_diagramm.h"

    Diagramm::Diagramm(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Diagramm)
    {
    ui->setupUi(this);
    }

    Diagramm::~Diagramm()
    {
    delete ui;
    }

    void Diagramm::onbuttonclicked()
    {
    Diagramm dia;
    dia.setModal(true);
    dia.exec();
    }
    @

    and Diagramm.h
    @#ifndef DIAGRAMM_H
    #define DIAGRAMM_H

    #include <QDialog>

    namespace Ui {
    class Diagramm;
    }

    class Diagramm : public QDialog
    {
    Q_OBJECT

    public:
    explicit Diagramm(QWidget *parent = 0);
    ~Diagramm();
    public slots:
    void onbuttonclicked();

    private:
    Ui::Diagramm *ui;
    };

    #endif // DIAGRAMM_H
    @

    If i click the button, i want to execute the onbuttonclicked() function from the Diagramm class.

    The Error is:
    there is no such slot QApplication:onbuttonclicked()

    I tried also
    QObject::connect(button, SIGNAL(clicked()),this, SLOT(onbuttonclicked()));

    -> invalid use of this in non-member function

    Can anyone help me? I am new at QT :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.