This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDevelop QT slot doesn´t work

Tags: qt, kdevelop, signals, slots qt, kdevelop, signals, slots qt, kdevelop, signals, slots
(comma "," separated)
LainOnTheWired
Registered Member
Posts
3
Karma
0

KDevelop QT slot doesn´t work

Thu Jan 17, 2019 7:54 am
Hallo community,

I want to write a QT application and the slots doesn´t work. I have insert the signal and slot in the QT designer and now i have the connection in the header file. That works, if i am not wrong i have to override the slot and can than program what it should do if i click the button but it doesn´t work it doesn´t go into the function. What i am doing wrong ? The exit button works fine.

Code: Select all
/********************************************************************************
** Form generated from reading UI file 'halloweltfenster6.ui'
**
** Created by: Qt User Interface Compiler version 5.6.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_HALLOWELTFENSTER6_H
#define UI_HALLOWELTFENSTER6_H

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_HalloWeltFenster6
{
public:
    QWidget *centralWidget;
    QPushButton *pushButton;
    QLabel *label;
    QPushButton *pushButton_2;
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;

    void setupUi(QMainWindow *HalloWeltFenster6)
    {
        if (HalloWeltFenster6->objectName().isEmpty())
            HalloWeltFenster6->setObjectName(QStringLiteral("HalloWeltFenster6"));
        HalloWeltFenster6->resize(400, 300);
        centralWidget = new QWidget(HalloWeltFenster6);
        centralWidget->setObjectName(QStringLiteral("centralWidget"));
        pushButton = new QPushButton(centralWidget);
        pushButton->setObjectName(QStringLiteral("pushButton"));
        pushButton->setGeometry(QRect(150, 10, 110, 39));
        label = new QLabel(centralWidget);
        label->setObjectName(QStringLiteral("label"));
        label->setGeometry(QRect(160, 130, 76, 23));
        pushButton_2 = new QPushButton(centralWidget);
        pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
        pushButton_2->setGeometry(QRect(150, 70, 110, 39));
        HalloWeltFenster6->setCentralWidget(centralWidget);
        menuBar = new QMenuBar(HalloWeltFenster6);
        menuBar->setObjectName(QStringLiteral("menuBar"));
        menuBar->setGeometry(QRect(0, 0, 400, 35));
        HalloWeltFenster6->setMenuBar(menuBar);
        mainToolBar = new QToolBar(HalloWeltFenster6);
        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
        HalloWeltFenster6->addToolBar(Qt::TopToolBarArea, mainToolBar);
        statusBar = new QStatusBar(HalloWeltFenster6);
        statusBar->setObjectName(QStringLiteral("statusBar"));
        HalloWeltFenster6->setStatusBar(statusBar);

        retranslateUi(HalloWeltFenster6);
        QObject::connect(pushButton, SIGNAL(clicked()), HalloWeltFenster6, SLOT(close()));
        QObject::connect(pushButton_2, SIGNAL(clicked()), HalloWeltFenster6, SLOT(update()));

        QMetaObject::connectSlotsByName(HalloWeltFenster6);
    } // setupUi

    void retranslateUi(QMainWindow *HalloWeltFenster6)
    {
        HalloWeltFenster6->setWindowTitle(QApplication::translate("HalloWeltFenster6", "HalloWeltFenster6", 0));
        pushButton->setText(QApplication::translate("HalloWeltFenster6", "Exit", 0));
        label->setText(QApplication::translate("HalloWeltFenster6", "TextLabel", 0));
        pushButton_2->setText(QApplication::translate("HalloWeltFenster6", "Text Aendern", 0));
    } // retranslateUi
   
    void update()
    {
        label->setText("Test");
    }

};

namespace Ui {
    class HalloWeltFenster6: public Ui_HalloWeltFenster6 {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_HALLOWELTFENSTER6_H
LainOnTheWired
Registered Member
Posts
3
Karma
0

Re: KDevelop QT slot doesn´t work

Fri Jan 18, 2019 9:00 am
OK i got it i have to override the update function in the HalloWeltFenster6 class as public slot now it works fine :).
Code: Select all
#ifndef HALLOWELTFENSTER6_H
#define HALLOWELTFENSTER6_H

#include <QMainWindow>

namespace Ui {
class HalloWeltFenster6;
}

class HalloWeltFenster6 : public QMainWindow
{
    Q_OBJECT

public:
    explicit HalloWeltFenster6(QWidget *parent = 0);
    ~HalloWeltFenster6();
   
public slots:
    void update();
   

private:
    Ui::HalloWeltFenster6 *ui;
};

#endif // HALLOWELTFENSTER6_H


Code: Select all
#include "halloweltfenster6.h"
#include "ui_halloweltfenster6.h"

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

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

void HalloWeltFenster6::update()
{
    ui->label->setText("Hallo Welt");
}


Thanks to anp_ at the KDevelop IRC channel :).
LainOnTheWired
Registered Member
Posts
3
Karma
0

Re: KDevelop QT slot doesn´t work

Fri Jan 25, 2019 8:49 am
For all how prefer a video tutorial for that check this, but the videos are in German.
https://www.youtube.com/watch?v=ALRVRrspn78


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, Sogou [Bot]