QObject::connect:没有这样的信号progressbarV::keyReleaseEvent()



我正在尝试创建一个项目,其中我有一个progressbarV类,它可以创建QProgressBar。我在我的主窗口中调用这个类。我的目标是在点击进度条时导航到另一个屏幕。为此,我尝试实现KeyRleaseEvent,但无论我做什么,我都会不断收到错误"QObject::connect:no such signal progressbarV::keyReleaseEvent()"。如果能为我解决这个问题提供任何帮助,我将不胜感激。

Please find my code below:-
mainwindow.h
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QWidget>
    #include <QProgressBar>
    #include <QLabel>
    #include <QPixmap>
    #include <QPushButton>
    #include <QtWidgets>
    #include <QProcess>
    #include "headerfiles/progressbarV.h"
    #include "headerfiles/redzonesettingsscreen.h"
    class progressbarH;
    class redZoneSettingsScreen;
    class MainWindow : public QMainWindow//,public QProcess
    {
        Q_OBJECT
    private:
        progressbarV *progressbar_V_left;
    public:
        MainWindow();
        ~MainWindow();
        void GetObjects(redZoneSettingsScreen *);
    private slots:
        void handleSettingsButtonPressed();
    /*protected:
        virtual void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;*/
    };
    #endif // MAINWINDOW_H
mainwindow.cpp
    #include "headerfiles/mainwindow.h"
    redZoneSettingsScreen *gotoSettingsScreen;
    MainWindow::MainWindow()
    {
        progressbar_V_left = new progressbarV;
        progressbar_V_left->setParent(this);
        progressbar_V_left->setGeometry(350,200,90,450);
        progressbar_V_left->setTitle("Height");
        progressbar_V_left->setData(labelCurHeight->getDataValue());
        progressbar_V_left->setMinVal(0);
        progressbar_V_left->setMaxVal(labelMaxHeight->getDataValue());
        connect(progressbar_V_left, SIGNAL (keyReleaseEvent()), this, SLOT 
            (handleSettingsButtonPressed()));
    }
    MainWindow::~MainWindow()
    {
        delete progressbar_V_left;
    }
    void MainWindow::GetObjects(redZoneSettingsScreen *button)
    {
        gotoSettingsScreen = button;
    }
    void MainWindow::handleSettingsButtonPressed()
    {
        gotoSettingsScreen->hide();
        gotoSettingsScreen->show();
        this->hide();
    }
    /*void MainWindow::keyReleaseEvent(QKeyEvent *event)
    {
    }*/
progressbarV.h
    #ifndef PROGRESSBARV_H
    #define PROGRESSBARV_H
    #include <QWidget>
    #include <QProgressBar>
    #include <QLabel>
    #include <QPixmap>
    class progressbarV: public QWidget
    {
        Q_OBJECT
    private:
        QProgressBar *progressbar_V;
        QLabel *labelRedDanger, *labelYellowWarning;
        float maxScaledHeight, redZoneScaledHeight, yellowZoneScaledHeight;
        int spn, spn_value;
        QString title;
        int data;
        short minVal;
        short maxVal;
    public:
        progressbarV();
        ~progressbarV();
        void setSPN(int);
        int getSPN();
        void setSPN_Value(int);
        int getSPN_Value();
        void setTitle(QString);
        QString getTitle();
        void setData(int);
        int getData();
        void setMinVal(short);
        short getMinVal();
        void setMaxVal(short);
        short getMaxVal();
        /*void setLowError(short);
        short getLowError();
        void setLowWarning(short);
        short getLowWarning();
        void setHighError(short);
        short getHighError();
        void setHighWarning(short);
        short getHighWarning();*/
        QProgressBar* getProgressBarV();
    protected:
        void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;
    };
   #endif // PROGRESSBARH_H
progressbarV.cpp
    #include "headerfiles/progressbarV.h"
    progressbarV::progressbarV()
    {
        progressbar_V = new QProgressBar;
        progressbar_V->setParent(this);
        progressbar_V->setStyleSheet("QProgressBar{ border: solid grey; border-
            width: 6; border-radius: 12; text-align: center;},    
        QProgressBar::chunk{background-color: limegreen; width: 0px; margin: 
            0px;}");
        progressbar_V->setGeometry(2,0,50,200);
        progressbar_V->setOrientation(Qt::Vertical);
        maxScaledHeight = (200*100)/120;
        redZoneScaledHeight = 200 - ((maxScaledHeight*105)/100);
        yellowZoneScaledHeight = 200 - ((maxScaledHeight*90)/100);
        QPixmap mypixRed(":/images/images/redZone.png");
        labelRedDanger = new QLabel;
        labelRedDanger->setParent(this);
        labelRedDanger->setGeometry(8,redZoneScaledHeight,38,3);
        labelRedDanger->setPixmap(mypixRed);
        QPixmap mypixYellow(":/images/images/yellowZone.png");
        labelYellowWarning = new QLabel;
        labelYellowWarning->setParent(this);
        labelYellowWarning->setGeometry(8,yellowZoneScaledHeight,38,3);
        labelYellowWarning->setPixmap(mypixYellow);
    }
    progressbarV::~progressbarV()
    {
        delete progressbar_V;
        delete labelRedDanger;
        delete labelYellowWarning;
    }
    void progressbarV::setSPN(int val)
    {
        spn = val;
    }
    int progressbarV::getSPN()
    {
        return spn;
    }
    void progressbarV::setSPN_Value(int val)
    {
        spn_value = val;
    }
    int progressbarV::getSPN_Value()
    {
        return spn_value;
    }
    void progressbarV::setTitle(QString mTitle)
    {
        title = mTitle;
    }
    QString progressbarV::getTitle()
    {
        return title;
    }
    void progressbarV::setData(int mData)
    {
        data = mData;
        progressbar_V->setValue(data);
    }
    int progressbarV::getData()
    {
        return data;
    }
    void progressbarV::setMinVal(short mMinVal)
    {
        minVal = mMinVal;
        progressbar_V->setMinimum(minVal);
    }
    short progressbarV::getMinVal()
    {
        return minVal;
    }
    void progressbarV::setMaxVal(short mMaxVal)
    {
        maxVal = mMaxVal;
        progressbar_V->setMaximum(maxVal);
    }
    short progressbarV::getMaxVal()
    {
        return maxVal;
    }
    QProgressBar *progressbarV::getProgressBarV()
    {
        return progressbar_V;
    }
    void progressbarV::keyReleaseEvent(QKeyEvent *event)
    {
    }
Since I am new to QT, kindly give me solutions in the form of code snippets
Thanks in advance,
Sam

您需要将keyReleaseEvent声明为公共SLOT

public slots:
    void keyReleaseEvent(QKeyEvent *); //Q_DECL_OVERRIDE;

以便QT可以使用旧的连接方式连接到它。

相关内容

  • 没有找到相关文章

最新更新