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

Posted

技术标签:

【中文标题】QObject::connect: 没有这样的信号progressbarV::keyReleaseEvent()【英文标题】:QObject::connect: No such signal progressbarV::keyReleaseEvent() 【发布时间】:2016-04-12 19:06:14 【问题描述】:

我正在尝试创建一个项目,其中我有一个创建 QProgressBar 的 progressbarV 类。我在我的主窗口中调用这个类。我的目标是当我点击进度条时导航到另一个屏幕。为此,我尝试实现 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::chunkbackground-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

【问题讨论】:

connect 命令只接受信号作为参数。 keyReleaseEvent 不是信号。 我将如何创建信号? 您可以创建一个处理 keyReleaseEvent 的函数,在该函数中调用您自己的信号。查找用于定义信号的示例代码。 【参考方案1】:

您需要将keyReleaseEvent 声明为公共SLOT

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

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

【讨论】:

以上是关于QObject::connect: 没有这样的信号progressbarV::keyReleaseEvent()的主要内容,如果未能解决你的问题,请参考以下文章

QObject::connect: 没有这样的信号错误 C++

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

QObject::connect: 没有这样的信号运行时警告 - 找不到原因

如果在调用 QObject::connect() 之前发出信号,如何避免竞争?

QObject::connect: 需要括号,信号 QSerialPort::readyRead in ..\voltage_sensor\dialop.cpp:41

如何修复QObject::connect:没有这样的插槽..将发送者连接到同一类中的插槽时[重复]