Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Connection QPushButton to a Function in main.cpp

    General and Desktop
    1
    1
    669
    Loading More Posts
    • 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
      suggi87 last edited by

      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 Reply Quote 0
      • First post
        Last post