Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connection QPushButton to a Function in main.cpp

Connection QPushButton to a Function in main.cpp

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 707 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    suggi87
    wrote on last edited by
    #1

    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 :(

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved